I need some help converting System.Web.Mail to System.Net.Mail to help send out e-mail notifications appropriately on some forms.
The old code snippet used is below:
MailMessage NotificationEmail = new MailMessage();
NotificationEmail.BodyFormat = MailMessage.IsBodyHtml;
NotificationEmail.From = "[email protected]";
//NotificationEmail.To = user;
NotificationEmail.To = "[email protected]";
NotificationEmail.Subject = "Notification : ";
NotificationEmail.BodyFormat = MailFormat.Html;
And some of the errors I'm getting include:
1.) 'System.Net.Mail.Message' does not contain a definition for 'BodyFormat' and no extension method 'BodyFormat' accepting a first argument of type 'System.Net.Mail.MailMessage' could be found.
2.) An object reference is required for the non-static field, method, or property 'System.Net.Mail.MailMessage.IsBodyHTML.get'
3.) Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress
4.) Property or indexer 'System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only.
...amongst other similar errors going on as well.
I'm quite certain most of these are inter-related to the main problem that I'm trying to solve which is just trying to convert the systems use of System.Web.Mail to System.Net.Mail.
I've done all the MVC and Telerik Updates I possibly could through NuGet, so those are up-to-date. I've Updated all the references as well so I know that's no longer an issue.
There may be a few things I need to change on Web.Config, but I'm not quite too sure what should be added or modified to it. I'm always weary of editing system files and assemblies, and people's tips on them as well so I try to avoid making those changes unless they are absolutely necessary.
Currently I'm using both System.Web.Mail and System.Net.Mail at the top of the file so it currently reads:
using System.Web.Mail;
using System.Net.Mail;
...as part of it's library includes. The system uses .NET Framework 4 by the way. Should I try updating it to .NET Framework 4.5?
Does anyone have any possible solutions for updating this block of code? It looks like from searching through here that a bunch of people are having similar issues, but everyone's questions appear to have mixed results/answers from forum moderators.
So that's why I submitted this question just to see what kind of responses I'd get.
Hopefully, this is enough information for you guys. If not, please let me know if you need additional info so I can provide it for you.
Thanks!
There are a couple of issues with your usage. This is how html emails are usually sent: