Sending Mail with SmtpClient

The SmtpClient class in the System.Net.Mail namespace allows you to send mail messages through the Simple Mail Transfer Protocol.

To send a simple text message, instantiate SmtpClient, set its Host property to your SMTP server address, and then call Send:


using System;
using System.Net;
using System.Net.Mail;

using System.Threading;
using System.IO;
using System.Text;
class ThreadTest
{
    static void Main()
    {
        SmtpClient client = new SmtpClient();
        client.Host = "mail.myisp.net";
        client.Send("from@adomain.com", "to@adomain.com", "subject", "body");
    }
}
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.