I was using the following code in order to send e-mails to my company's intranet a开发者_JS百科ccounts from a VB.NET 2003 aplication. However this code was marked as no longer valid when I migrated the application after installing Visual Studio 2005. Could you help me modifying this code in order for my application to compile succesfully?
Dim email As New System.Web.Mail.MailMessage
email.To = "some@Email"
email.From = "my_Application"
email.Subject = "BE CAREFULL! Errors encountered"
email.Body = "messagebody"
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer = "###.###.###.###"
Try
System.Web.Mail.SmtpMail.Send(email)
Catch ehttp As System.Web.HttpException
Console.WriteLine(ehttp.InnerException.InnerException.Message)
End Try
The namespace you should be using is .. using System.Net.Mail;
If I remember right, the jump from vs2003 to vs2005 also jumped from .net1.1 to .net2. Which means System.Web.Mail.MailMessage was marked as obsolete. .net 2.0 has System.net.mail.smtpcleint which works about the same but has the added benefit of being more Object Orientated.
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient%28VS.80%29.aspx
精彩评论