.NET发送邮件
来源:互联网 发布:2017网络行业利润率 编辑:程序博客网 时间:2024/06/17 00:33
首先导入using System.Net.Mail;
public void SendEmail(string sendToList, string attachment, string subject, string mailBody)
{
MailMessage mail = new MailMessage(); sendToList = sendToList.Trim().TrimEnd(';');
if (sendToList.Length == 0)
{ throw new Exception("程序没有获取到文件的收件人列表,请检查是否没有设置!"); }
mail.From = new MailAddress("Volunteer123@163.com");
foreach (string to in sendToList.Split(';'))
{
mail.To.Add(to); }
mail.IsBodyHtml = false;
mail.Subject = subject;
mail.Body = mailBody;
mail.SubjectEncoding = Encoding.GetEncoding("gb2312");
mail.BodyEncoding = Encoding.GetEncoding("gb2312");
if (attachment.Length > 0)
{ mail.Body = mailBody + "\n\r随邮件带附件:" + attachment;
if (File.Exists(attachment))
{
Attachment mailAttach = new Attachment(attachment);
mail.Attachments.Add(mailAttach);
}
}
SmtpClient smtp = new SmtpClient("smtp.163.com");
smtp.Credentials = new System.Net.NetworkCredential("Volunteer123@163.com", "密码");
smtp.Send(mail);
mail.Dispose();
}
{
MailMessage mail = new MailMessage(); sendToList = sendToList.Trim().TrimEnd(';');
if (sendToList.Length == 0)
{ throw new Exception("程序没有获取到文件的收件人列表,请检查是否没有设置!"); }
mail.From = new MailAddress("Volunteer123@163.com");
foreach (string to in sendToList.Split(';'))
{
mail.To.Add(to); }
mail.IsBodyHtml = false;
mail.Subject = subject;
mail.Body = mailBody;
mail.SubjectEncoding = Encoding.GetEncoding("gb2312");
mail.BodyEncoding = Encoding.GetEncoding("gb2312");
if (attachment.Length > 0)
{ mail.Body = mailBody + "\n\r随邮件带附件:" + attachment;
if (File.Exists(attachment))
{
Attachment mailAttach = new Attachment(attachment);
mail.Attachments.Add(mailAttach);
}
}
SmtpClient smtp = new SmtpClient("smtp.163.com");
smtp.Credentials = new System.Net.NetworkCredential("Volunteer123@163.com", "密码");
smtp.Send(mail);
mail.Dispose();
}
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- .net发送接收邮件
- 使用.NET发送邮件
- asp.net发送邮件
- ASP.NET发送邮件
- .NET下发送邮件
- asp.net发送邮件
- .net 2.0 邮件发送
- .net中发送邮件
- c#.net发送邮件
- .Net 发送邮件
- .net发送邮件
- NET 邮件发送
- .NET邮件发送
- 使用.NET发送邮件
- RESTful WebServices 读书笔记
- Android控件之Gallery探究
- UIPopoverController在ARC环境下用法注意
- Mysql表引擎优化
- STM32 GPIO入门学习
- .NET发送邮件
- android api 中文 (75)—— AdapterView.OnItemClickListener
- 解决WINDOWS7下打开VC6错误
- android TabHost小结
- 超强JSP防SQL注入攻击
- Ksoap2 与 JAX-WS 相互传送自定义类
- 如何将TabBar放置底部?
- 自定义Toast、程序退出时Toast也退出、Toast的用法
- Python模块包中__init__.py文件的作用