Thursday, 30 September 2010

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

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

While implementing the email functionality from my website, suddenly i recieve this error.

MailMessage m = new MailMessage();
m.From = "abc@indihub.com";

in second line i received this error. this is because you can not directly convert the string type to mail data type. To fix this error you need to convert you string email address to mail data type.

Same you can achieve by

MailMessage m = new MailMessage();
m.From = new System.Net.Mail.MailAddress("abc@indihub.com");

This line will create a object of mail. Where MailAddress() is a class constructor, takes an email address as an input parameter.

No comments:

Post a Comment