Mail from WebMail to Gmail

Add Namespaces

using System.Net;
using System.Web.Mail;

 

MailMessage msg = new MailMessage();
msg.Body = TextBox4.Text;
string smtpServer = “smtpserver”;
string userName = “username”;
string password = “password;
int cdoBasic = 1;
int cdoSendUsingPort = 2;
if (userName.Length > 0)
{
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpserver”, smtpServer);
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”, 25);
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendusing”, cdoSendUsingPort);
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”, cdoBasic);
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendusername”, userName);
msg.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendpassword”, password);
}
msg.To = TextBox1.Text;
msg.From = TextBox2.Text;
msg.Subject =TextBox3.Text;
msg.BodyEncoding = System.Text.Encoding.UTF8;
SmtpMail.SmtpServer = smtpServer;
SmtpMail.Send(msg);
Label6.Text = “success”;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s