class SendEmail
{
static void Main(string[] args)
{
string from = "发件人@yingu.com";
string fromer = "赵海莹";
string to = "收件人@yingu.com";
string toer = "刘春喜";
string Subject = "逾期数据报表";
string file = string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "ReprotingTemp\\逾期订单列表.xls");
string Body = "逾期数据报表";
//企业邮箱smtp
string SMTPHost = "smtp.qiye.163.com";
string SMTPuser = "发件人@yingu.com";
string SMTPpass = "******(发件人邮箱密码)";
sendmail(from, fromer, to, toer, Subject, Body, file, SMTPHost, SMTPuser, SMTPpass);
}
/// <summary>
/// C#发送邮件函数
/// </summary>
/// <param name="from">发送者邮箱</param>
/// <param name="fromer">发送人</param>
/// <param name="to">接受者邮箱</param>
/// <param name="toer">收件人</param>
/// <param name="Subject">主题</param>
/// <param name="Body">内容</param>
/// <param name="file">附件</param>
/// <param name="SMTPHost">smtp服务器</param>
/// <param name="SMTPuser">邮箱</param>
/// <param name="SMTPpass">密码</param>
/// <returns></returns>
private static bool sendmail(string sfrom, string sfromer, string sto, string stoer, string sSubject, string sBody, string sfile, string sSMTPHost, string sSMTPuser, string sSMTPpass)
{
////设置from和to地址
MailAddress from = new MailAddress(sfrom, sfromer);
MailAddress to = new MailAddress(sto, stoer); ////创建一个MailMessage对象
MailMessage oMail = new MailMessage(from, to); //// 添加附件
if (sfile != "")
{
oMail.Attachments.Add(new Attachment(sfile));
} ////邮件标题
oMail.Subject = sSubject; ////邮件内容
oMail.Body = sBody; ////邮件格式
oMail.IsBodyHtml = false; ////邮件采用的编码
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); ////设置邮件的优先级为高
oMail.Priority = MailPriority.High; ////发送邮件
SmtpClient client = new SmtpClient();
////client.UseDefaultCredentials = false;
client.Host = sSMTPHost;
//企业邮箱需设置端口,个人邮箱不需要
client.Port = ;
client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(oMail);
return true;
}
catch (Exception err)
{
//Response.Write(err.Message.ToString());
return false;
}
finally
{
////释放资源
oMail.Dispose();
} }
}

最新文章

  1. Java设计模式-访问者模式(Visitor)
  2. HDU 1044 Collect More Jewels(BFS+DFS)
  3. Cocos2d-x——Cocos2d-x 屏幕适配新解【转载】
  4. 由 OR 引起的死循环
  5. Oracle INTERVAL DAY TO SECOND数据类型
  6. IIS HTTP重定向到HTTPS
  7. Java中的局部变量表及使用jclasslib进行查看
  8. Automatic Generation of Animated GIFs from Video论文研读及实现
  9. USACO JAN14 奶牛冰壶运动 凸包+判定
  10. [原创]基于Zybo SDIO WiFi模块调试
  11. puppeteer 拦截页面请求
  12. 问题 1923: [蓝桥杯][算法提高VIP]学霸的迷宫 (BFS)
  13. Python可迭代对象中的添加和删除(add,append,pop,remove,insert)
  14. C++ Exception机制
  15. Qt ------ QFileDialog
  16. JAVA8 in Action:行为参数化,匿名类及lambda表达式的初步认知实例整理
  17. Django 设置media static
  18. 异常could not retrieve snapshot
  19. poj1273
  20. Django 2.0 学习(20):Django 中间件详解

热门文章

  1. Ubuntu下查看服务器cpu是否支持VT
  2. Python爬虫+颜值打分,5000+图片找到你的Mrs. Right
  3. Android 6.0权限分组
  4. Java反射机制实战——字段篇
  5. VC++函数只被调用一次
  6. 使用Spring框架的步骤
  7. javascript入门经典(第五版)-清华出版社之“经典”错误
  8. Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout
  9. NGS数据格式介绍
  10. chr()返回值是当前整数对应的 ASCII 字符。