MailMessage+SmtpClient 发送邮件
2016-04-26 10:41
716 查看
private static void SendMail(string to, string from,string content) { string subject="Mail Title";//邮件标题 string strSmtpServer= "smtp.163.com";//服务器 string strSmtpUserName = "登录账号@163.com";//登录用户 string strSmtpUserPwd = "登录密码";//登录密码 if (string.IsNullOrEmpty(to)) return; MailMessage mail = new MailMessage(from, to, subject, content); //创建邮件信息 if (File.Exists("D:/login.png")) { Attachment attach=new Attachment("D:/login.png"); //添加附件 //FileStream file = new FileStream("D:/login.png", FileMode.Open); //Attachment attachStream = new Attachment(file, "login.png"); //通过文件流添加附件 mail.Attachments.Add(attach); } SmtpClient client = new SmtpClient(strSmtpServer); //创建SMTP客户端 try { client.Credentials = new System.Net.NetworkCredential(strSmtpUserName, strSmtpUserPwd);//登录客户端 client.Send(mail);//发送邮件 邮件发送方必须和登录用户一致 } catch (Exception) { } }
相关文章推荐
- DAY6:leetcode #11 Container With Most Water
- linker command failed with exit code 1 (use -v to see invocation)错误调试
- cpu_relax( )-----对自选循环等待(spin-wait loops)操作的优化【转】
- mac os 终端提示 you have new mail
- 人工智能对战游戏程序会怎样?奥创大战贾维斯吗!
- UVA 818 Cutting Chains
- postmain 导致浏览器两次请求
- LintCode: Paint House II
- (整理)IIS 7 503 "service unavailable" errors
- AD的一些信息
- paintEvent调用时机
- LogCat里的错误提示 FATAL EXCEPTION: main
- LintCode:Paint House
- HDU 2476 String painter 区间dp
- 概率图模型
- bnu 51641 Certain Maze(bfs)(北师16校赛)
- caption标签,为表格添加标题和摘要 summary a mail
- bnu 51638 Air Hockey(三分+二分)(北师16校赛)
- hdu1302The Snail
- bnu 51640 Training Plan(类似区间dp)(北师16校赛)