Paul Maddox

Software development team leader specialising in Microsoft Visual C# and C++ from the Northwest of England. Experience working in a globalised business and team; understanding of enterprise business operation and practices; experience reporting to executive management Skills in numerous languages and technologies; knowledge of formal software development lifecycle; experience of architecture design

Monday, May 28, 2007

Sending SMTP Email in C# - .NET 1.x and .2.0

Microsoft, at least with software development, have a tendency to be reasonably consistent, which is why I was surprised recently that the class structure of .NET 1.x and 2.0 have changed somewhat.

Code for sending email, .NET 1.1:

using System.Web.Util;
MailMessage mail = new MailMessage("from@addr.com", "to@addr.com",
"My subject", "Text body");
SmtpMail smtp("relay.server.com");
string res = SmtpMail.Send(mail);

Code for sendmail email, .NET 2.0:

using System.Net.Mail;
MailMessage mail = new MailMessage("from@addr.com", "to@addr.com",
"My subject", "Text body");
SmtpClient smtp("relay.server.com");
string res = smtp.Send(mail);

0 Comments:

Post a Comment

<< Home