Solved

Which email code should I use?

Posted on 2012-03-26
7
281 Views
Last Modified: 2012-08-13
Hi
My code monitors a website and then sends an email when the site is updated. I have Outlook code that can send an email.
I did some research online, and most sites recommended to use System.Web.mail instead. However, when I type
Dim oMail As New MailMessage
I get a message from Visual Studio that
'System.Web.Mail.MailMessage' is obsolete: 'The recommended alternative is System.Net.Mail.MailMessage. http://go.microsoft.com/fwlink/?linkid=14202'

Which mail library should I use?
Thanks
0
Comment
Question by:jdhackett
7 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 37766761
System.Net.Mail is easier to use than System.Web.Mail in most circumstances.  Both rely on having access to SMTP server.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 150 total points
ID: 37766785
Anything marked as "obsolete" generally means you should use the other. IIRC, "obsolete" items have the potential to be removed in future updates, though I don't think MS has removed anything since the change from 1.x to 2.0.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 150 total points
ID: 37766800
System.Web.Mail is deprecated as of .Net Framework 3.5 so you should use System.Net.Mail as support for System.Web.Mail may be dropped in a future version of the framework
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:jdhackett
ID: 37770176
System.Web.Mail it is then. Thanks.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37770951
???   Isn't that the opposite of what everyone here said?
0
 
LVL 1

Assisted Solution

by:alrosmarz
alrosmarz earned 200 total points
ID: 37771586
i use this..

 try
            {
                StringBuilder emailMessage = new StringBuilder();
                System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
                email.From = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["MailFrom"].ToString());
                email.To.Add(new MailAddress(Para));
                if (!string.IsNullOrEmpty(CC))
                    email.CC.Add(CC);
                if (!string.IsNullOrEmpty(CCO))
                    email.Bcc.Add(CCO);
                email.Subject = Subject;
                email.Body = BodyCorreo;
                email.IsBodyHtml = true;

                SmtpClient client = new SmtpClient();
                client.Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["SMTPPort"].ToString());
                client.Host = System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString();
                client.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings       ["SMTPUser"].ToString(), System.Configuration.ConfigurationManager.AppSettings["PasswordMailFrom"].ToString());
                client.Send(email);
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
0
 
LVL 1

Author Comment

by:jdhackett
ID: 37804983
Sorry, meant to say "System.Net.Mail it is then"!
Thanks all for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now