Search This Blog

Wednesday, October 10, 2007

Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'

I got error "Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress' "

MailMessage msg = new MailMessage();
msg.From = "info@xxx.com";
msg.To = "comments@xx.com";
msg.Bcc = "keith@xxx.com";

msg.Subject = "Comment";
msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = Global.smtp;

To solve the issue, i change to below code

MailMessage msg = new MailMessage();
msg.From = new System.Net.Mail.MailAddress("info@xxx.com");
msg.To.Add("comments@xx.com");
msg.Bcc.Add("keith@xxx.com");

msg.Subject = "Comment"; msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";

SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = Global.smtp;

5 comments:

me said...

You may have to try to use System.web.**** as i did on a Server which i am NOT allowed to update the version of the .Net Framework...
HTH

JAaronAnderson.com

Anonymous said...

Took me time to read the whole article, the article is great but the comments bring more brainstorm ideas, thanks.

- Johnson

Fishing_Frenzy said...

Thanks, that worked perfectly

Praveen Solomon said...

Thnks Buddy its WORKSSS...

agnel said...

many many Thnks Buddy its WORKSss