Tuesday, May 8, 2012

send email from asp.net app

i configure all setting for send email using c# but when i execute than i get the following error
The requested address is not valid in its context

my code is

MailMessage mail = new MailMessage();
mail.From = new MailAddress("from@gmail.com");
mail.Subject = "Test Email";

string Body = "<b>Welcome to CodeDigest.Com!!</b>";
mail.Body = Body;
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["SMTP"];
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
smtp.EnableSsl = true;



<add key="SMTP" value="smtp.gmail.com"/>

<add key="FROMEMAIL" value="mail@gmail.com"/>

<add key="FROMPWD" value="password"/>


No comments:

Post a Comment