ali raza

C#, .Net ,Asp.net and my thoughts

how to send mail smtp with authentication with web.mail class

hi i used following code

MailMessage message = new MailMessage();

message.To = "myemailaccount@yahoo.com";

message.From = "myemailaccount@thecrystalrosary.com";
message.Subject = "Testing Internet SmtpMail";
message.BodyFormat = MailFormat.Html;

message.Body = "body";

message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.thecrystalrosary.com");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2); //2 to send using SMTP over the network
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); //1 = basic authentication
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");

try
{
SmtpMail.Send(message);
}
catch (Exception e)
{
// trap here
}

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

%d bloggers like this: