概述
首先安装mailkit
然后 控制器
using Microsoft.AspNetCore.Mvc;
using MimeKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Threading.Tasks;
//SmtpClient smtpClient = System.Net.Mail.SmtpClient;
namespace emil.Controllers
{
public class Get : Controller
{
public void xx() {
//收件人邮箱
string mailName = "22580557@qq.com";
//发送的标题
string title = "测试数据";
//发送的内容
string bobyText = "吃鸡丁拌面!";
// 邮件服务器smtp.qq.com表示qq邮箱服务器
string host = "smtp.qq.com";
// 发送端账号
string userName = "5068449@qq.com";
// 发送端授权码,需要在邮箱获取授权码
string pwd = "vtwssafdobjab";
MimeMessage message = new MimeMessage();
//发件人
message.From.Add(new MailboxAddress("T.Shiller", userName));
//收件人
message.To.Add(new MailboxAddress(title, mailName));
// message.To.Add(new MailboxAddress(title,mailName ));
//标题
message.Subject = title;
//正文内容,发送
message.Body = new BodyBuilder
{
HtmlBody = bobyText
}.ToMessageBody();
try
{
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
//Smtp服务器
client.Connect(host, 587, false);
//登录,发送
client.Authenticate(userName, pwd);
client.Send(message);
//断开
client.Disconnect(true);
}
}
catch (Exception)
{
throw;
}
}
}
}
最后
以上就是香蕉电灯胆为你收集整理的ASP.Net core 使用mailkit发送邮件的全部内容,希望文章能够帮你解决ASP.Net core 使用mailkit发送邮件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复