C#System.Net.Mail采用简单邮件传输协议发送邮件

引用:

using System.Net.Mail;

public class EmailHelper
        {
            public static bool SendEmail(string title, string body, string address)
            {
                try
                {
                    MailAddress from = new MailAddress("xxx@xxx.com", "xxx"); //发送源邮箱地址和名称
                    MailAddress to = new MailAddress(address);       //接收者邮箱地址
                    MailMessage message = new MailMessage(from, to);    //新建邮件
                    message.Subject = title;    //邮件标题
message.Body
= body; //邮件正文 message.IsBodyHtml = true; //邮件正文格式
using (SmtpClient client = new SmtpClient("255.255.255.255", 50)) //服务器和端口号 { client.Credentials = new System.Net.NetworkCredential("xxx", "password"); //用户名和密码 client.Send(message); } return true; } catch (Exception) { return false; } } }

 

posted @ 2015-07-30 16:48  HotSky  阅读(207)  评论(0编辑  收藏  举报