.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 ...
随机推荐
- 使用Jenkins与Docker持续集成与发布NetCore项目(实操篇)
使用Jenkins与Docker持续集成与发布NetCore项目(教程一) 原文地址:https://www.cnblogs.com/Jackyye/p/12588182.html 基本环境 该教程的 ...
- bugku论剑场web解题记录
前言 国庆这几天感觉没什么好玩的地方,家又离的太远,弱鸡的我便决定刷刷题涨涨知识,于是就有了这篇文章.. 正文 写的不对的地方欢迎指正 web26 打开直接就是代码,这应该就是一道代码审计的题了 这里 ...
- NOI ONLINE 提高组 序列 根据性质建图
题目链接 https://www.luogu.com.cn/problem/P6185 题意 应该不难懂,跳过 分析 说实话第一眼看到这题的时候我有点懵,真不知道怎么做,不过一看数据,还好还好,暴力能 ...
- Java 注解 So Easy!!!
Java注解 Annotations, a form of metadata, provide data about a program that is not part of the program ...
- Oracle 10g客户端的安装和配置
1.双击Oracle11g_database安装目录下的Setup.exe. 2.选择“基本安装”,设置“安装位置”,填写“数据库名”和“口令”,点击“下一步”. 3.点击“下一步”. 4.一般会出现 ...
- 1642: 【USACO】Payback(还债)
1642: [USACO]Payback(还债) 时间限制: 1 Sec 内存限制: 64 MB 提交: 190 解决: 95 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 &quo ...
- xmind转为markdown
先将xmind导出为.opml 将opml导入Typora (需要安装pandoc)
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- 典型的MVC架构图
通常,当使用MVC时,应用程序中的每个逻辑部分都有一个单一的控制器.在这些控制器的前面还有一个Router:这是一个看门人,用于确定用户请求的内容,以便应用程序满足用户需要.常用php的mvc框架:Y ...
- 初始WebApi(1)
如果你要问我WebApi是干嘛,我只能说它是的给数据.哈哈哈哈哈,这几天也才刚刚了解了解关于WebApi的知识,今天就来谈谈吧. 1.创建WebApi项目 第一步:选择ASP.NET Web应用程序 ...