• 使用MailMessage和SmtpClient发送邮件


     Console.WriteLine("开始发送邮件....");
                //1.MailMessage
                //1.创建一封邮件
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("szyuxueliang@163.com");
                msg.To.Add(new MailAddress("1027206433@qq.com"));
                msg.Subject = "======去给我带份饭。=======";
                msg.SubjectEncoding = Encoding.GetEncoding("gb2312");
                msg.Body = "==================在中午12:00之前把饭送过来。================";

                //创建一个html格式的文档
                AlternateView aview = AlternateView.CreateAlternateViewFromString("在中午<h1><font color=\"red\">12:00</font></h1>之前把饭送过来。<br/><img src=\"cid:img001\"/>", Encoding.UTF8, "text/html");

                //为邮件中增加一张图片
                LinkedResource resource = new LinkedResource(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\loading.gif");
                resource.ContentId = "img001";

                aview.LinkedResources.Add(resource);
                msg.AlternateViews.Add(aview);

                //为邮件增加一些附件
                Attachment attchFile1 = new Attachment(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\addarticle.gif");
               // Attachment attchFile2 = new Attachment(@"E:\HTML.5与CSS.3权威指南.pdf");
                //Attachment attchFile3 = new Attachment(@"E:\传智播客视频\【ASP.NET≠拖控件!】-传智播客ASP.NET高手之路视频教程01_单线程缺点和简单多线程操作(1).zip");

                msg.Attachments.Add(attchFile1);
               // msg.Attachments.Add(attchFile2);
                //msg.Attachments.Add(attchFile3);

     

                //2.SmtpClient

                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.163.com";
                smtp.Credentials = new NetworkCredential("szyuxueliang", "哈哈不告诉你!");
                smtp.Send(msg);
                Console.WriteLine("发送完毕!");
                Console.ReadKey();

  • 相关阅读:
    C# 让程序自动以管理员身份运行
    [转]SAP算号器 license key Developer Access Key 完美解决方案
    【原创】项目性能优化全纪录(一) 存储过程优化
    treeview的遍历
    .NET求职笔试题目(续)
    SQL server 数据同步 Merge 的一个小bug
    use Stored procedure return a tabel(存储过程返回table)
    四种sql server 数据库分页的测试
    十五个世界最顶级的技术类博客网站
    层的拖动与隐藏
  • 原文地址:https://www.cnblogs.com/yxlblogs/p/3038247.html
Copyright © 2020-2023  润新知