.Net Core Send Email
1、安装Nuget包MailKit,引用命名空间。
using MailKit.Net.Smtp;
using MimeKit;
注意:引用MailKit对应最新版本

2、定义收发地址和标题
MimeMessage message = new MimeMessage();
MailboxAddress from = new MailboxAddress("Admin","admin@example.com");
message.From.Add(from);
MailboxAddress to = new MailboxAddress("User", "user@example.com");
message.To.Add(to);
message.Subject = "This is email subject";
注意:Admin,User分别对应发送接收邮箱前缀
3、编写内容
BodyBuilder bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "<h1>Hello World!</h1>";
bodyBuilder.TextBody = "Hello World!";
message.Body = bodyBuilder.ToMessageBody();
注意:也可以自定义模板,插入图片等等。
4、连接SMTP服务器发送邮件
SmtpClient client = new SmtpClient();
client.Connect("smtp_address_here", port_here, true); //例如:smtp.exmail.qq.com,465
client.Authenticate("admin@example.com", "password"); //发送邮件的账户密码
client.Send(message);
client.Disconnect(true);
client.Dispose();
.Net Core Send Email的更多相关文章
- Try to write a script to send e-mail but failed
#-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...
- python auto send email
/*************************************************************************** * python auto send emai ...
- Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email
Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email. (文档 I ...
- Send Email in Robot Framework Python Using Gmail
转载自:http://seleniummaster.com/sitecontent/index.php/selenium-robot-framework-menu/selenium-robot-fra ...
- 5 Ways to Send Email From Linux Command Line
https://tecadmin.net/ways-to-send-email-from-linux-command-line/ We all know the importance of email ...
- [476] Database Mail is not enabled for agent notifications. Cannot send e-mail to
配置完DB Mail后JOB的的通知邮件不能发送,日志报错476] Database Mail is not enabled for agent notifications. Cannot send ...
- Send Email in .NET Core 2.0
在.NET Core 1.0 中,SMTP Client代码并没有被移植,直到.NET Core 2.0的发布.使用下面的代码: static void Main(string[] args) { S ...
- Send email alert from Performance Monitor using PowerShell script (检测windows服务器的cpu 硬盘 服务等性能,发email的方法) -摘自网络
I have created an alert in Performance Monitor (Windows Server 2008 R2) that should be triggered whe ...
- Send Email
private string SendEmail(string mailTo, string body, ref int sendresult) { string errorEmailAddress ...
随机推荐
- vscode快速生成html模板(vscode快捷键"!"生成html模板)
问题: 在vscode中新建test.html, 内容是空白的,输入"!",然后按tap键 ,没有生成常见的html模板,也就是如下: 输入! html html:5 DOCTYP ...
- win10 Redis闪退问题
问题:双击redis-server.exe,闪退 解决办法:win+R,输入cmd进入命令行模式,接着cd进入Redis安装根目录,再输入:redis-server.exe redis.windows ...
- 牛客网剑指offer【Python实现】——part1
斐波那契数列 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,n<=39). 循环实现,时间复杂度n def Fibonacci(self, ...
- 解决python3使用cx_Freeze打包成exe后不能运行
我使用的是python3.4,在使用cx_Freeze打包成exe后发现有些打包后程序能够运行,但是有些无法运行 这是控制台报错 经过多方查找发现原来是windows缺少一些python的扩展包 如下 ...
- 服务器模型---socket!!!
/*********************服务器模型******************/ 一.循环服务器:循环服务器在同一时刻只可以相应一个客户端请求: 二.并发服务器:并发服务器在同一时刻可以相 ...
- 洛谷5026 Lycanthropy 差分套差分
题目链接 https://www.luogu.com.cn/problem/P5026 题意 在一个长度为m的序列中,每次给一个下标x,和一个权值v,然后从x-v*3到x-v*2单调递增,从x-v*2 ...
- POJ 1062 昂贵的聘礼 最短路+超级源点
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...
- python之常用模块ymal
在学习python如何操作yml文件之前,我们先科普一下yml的格式 yaml是专门写配置文件的语言,非常简洁和强大,比json更加方便 YAML 语言(发音 /ˈjæməl/ )的设计目标,就是方便 ...
- localStorage中一个数组嵌套一个数组的怪相
localStorage中一个数组嵌套一个数组的怪相 需求:向本地存储中循环添加对象 思路 : 先完成点击事件中添加本地存储功能,当刷新时使用一个数组记录已经存储下来的数据,并在点击事件中将新生成 ...
- 剖析手写Vue,你也可以手写一个MVVM框架
剖析手写Vue,你也可以手写一个MVVM框架# 邮箱:563995050@qq.com github: https://github.com/xiaoqiuxiong 作者:肖秋雄(eddy) 温馨提 ...