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

by Ali Raza Zaidi on November 19, 2008

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
}

Comments on this entry are closed.

Previous post:

Next post: