本文共 1513 字,大约阅读时间需要 5 分钟。
public class SendEmail { private string _serverUrl; private string _userName; private string _userPwd; private string _userUrl; private string _receiveUrl; private string _title; private string _body; public string ServerUrl { get { return _serverUrl; } set { _serverUrl = value; } } public string UserName { get { return _userName; } set { _userName = value; } } public string UserPwd { get { return _userPwd; } set { _userPwd = value; } } public string UserUrl { get { return _userUrl; } set { _userUrl = value; } } public string ReceiveUrl { get { return _receiveUrl; } set { _receiveUrl = value; } } public string Title { get { return _title; } set { _title = value; } } public string Body { get { return _body; } set { _body = value; } } public void SendMail(SendEmail email) { //发送邮件,直接发送带有用户名,密码的邮件,因为密码没有加密。 System.Net.Mail.SmtpClient client = new SmtpClient(email.ServerUrl); client.UseDefaultCredentials = false; //下面的用户名密码填写自己在163的用户名密码,也可以修改上面的SMTP服务器 client.Credentials = new System.Net.NetworkCredential(email.UserName, email.UserPwd); client.DeliveryMethod = SmtpDeliveryMethod.Network; //创建MailMessage对象,参数分别为 发件人地址,收件人地址 ,信件标题,信件正文 System.Net.Mail.MailMessage message = new MailMessage(email.UserUrl, email.ReceiveUrl, email.Title, email.Body); message.BodyEncoding = System.Text.Encoding.Default; //编码 message.IsBodyHtml = true; //是否是HTML代码 try { client.Send(message); //发送 } catch { } } } 来源于:www.hackbadboy.com B.B.S.T 信息安全团队 转载于:https://www.cnblogs.com/secbook/archive/2011/12/16/2654909.html