Quantcast
Channel: isaced - C#
Viewing all articles
Browse latest Browse all 10

[C#]SMTP邮件发送小例子

$
0
0

一个最简单明了的C#发送邮件例子。

全注释,CSDN上看了下资料,还是蛮简单的!

using System.Net.Mail;//引入Mail命名空间

namespace SendMaill
{
    class Program
    {
        static void Main(string[] args)
        {
            MailMessage mail = new MailMessage();

            //设置邮件标题    
            mail.Subject = "测试邮件!";
            //设置发信人地址
            mail.From = new MailAddress("isaced@163.com");
            //设置收信人地址(可多个)
            mail.To.Add("6401159@qq.com");
            //邮件正文
            mail.Body = "Test~~~~~~~~~~~";


            SmtpClient client = new SmtpClient();

            //SMTP服务器地址
            client.Host = "smtp.163.com";
            //连接SMTP服务器的用户名、密码
            client.Credentials = new System.Net.NetworkCredential("用户名", "密码");
            //设置为SMTP发送
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            //发送邮件
            client.Send(mail);
        }
    }
}

Viewing all articles
Browse latest Browse all 10

Trending Articles