欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.net core 发送邮件

程序员文章站 2022-06-30 22:47:00
var message = new MimeMessage(); //发送方 message.From.Add(new MailboxAddress("liyy", "xxxxx.com")); //接受方 message.To.Add(new MailboxAddress("Mrs. li", " ......
   var message = new mimemessage();
            //发送方
            message.from.add(new mailboxaddress("liyy", "xxxxx.com"));
            //接受方
            message.to.add(new mailboxaddress("mrs. li", "xxxxx.com"));
            //标题
            message.subject = "周末去哪嗨?";
            //文字内容
            message.body = new textpart("plain") { text = "上海一日游" };
            //开始发送
            using (var client = new mailkit.net.smtp.smtpclient())
            {
                client.servercertificatevalidationcallback = (s, c, h, e) => true;
                client.connect("smtp.live.com", 465, true);
                client.authenticationmechanisms.remove("xoauth2");
                client.authenticate("发送方邮箱", "发送方邮箱smtp授权码");
                client.send(message);
                client.disconnect(true);
            }