码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-07-30 18:45:04      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

引用:

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; } } }

 

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

标签:

原文地址:http://www.cnblogs.com/RedSky/p/4689834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!