Using the new ASP.NET v2 SMTP Class

Due to the fact that System.Web.Mail.SmtpMail is obsolete now, here’s a little Snippet for you which shows the use of the replacement class. You can leave out the SMTPServer stuff if you’re Mailserver runs locally and doesn’t require local authentication.

using System.Net.Mail;

  protected void Button1_Click(object sender, EventArgs e)
    {
        string SMTPServer = "mail.sunlab.de";
        string fromAddress = "Andreas.Kraus@sunlab.de";
        string fromName = "Andreas Kraus";
        string toAddress = "info@kmc-home.com";
        string toName = "KMC Studios";
        string msgSubject = "Meeting";
        string msgBody = "Today";        
      
        SmtpClient client = new SmtpClient(SMTPServer);
        client.Credentials= new System.Net.NetworkCredential("Andreas.Kraus@sunlab.de", "thepw");
        MailAddress from = new MailAddress(fromAddress, fromName);
        MailAddress to = new MailAddress(toAddress, toName);
        MailMessage message = new MailMessage(from, to);
      
        message.Subject = msgSubject;
        message.Body = msgBody;
    
        client.Send(message);
    }

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment