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的更多相关文章

  1. Try to write a script to send e-mail but failed

    #-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...

  2. python auto send email

    /*************************************************************************** * python auto send emai ...

  3. 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 ...

  4. Send Email in Robot Framework Python Using Gmail

    转载自:http://seleniummaster.com/sitecontent/index.php/selenium-robot-framework-menu/selenium-robot-fra ...

  5. 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 ...

  6. [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 ...

  7. Send Email in .NET Core 2.0

    在.NET Core 1.0 中,SMTP Client代码并没有被移植,直到.NET Core 2.0的发布.使用下面的代码: static void Main(string[] args) { S ...

  8. 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 ...

  9. Send Email

    private string SendEmail(string mailTo, string body, ref int sendresult) { string errorEmailAddress ...

随机推荐

  1. [最短路,floyd] Codeforces 1202B You Are Given a Decimal String...

    题目:http://codeforces.com/contest/1202/problem/B B. You Are Given a Decimal String... time limit per ...

  2. 李宏毅老师机器学习课程笔记_ML Lecture 0-2: Why we need to learn machine learning?

    引言: 最近开始学习"机器学习",早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程.今天听了一课,感觉非常棒,通俗易懂,而又能够抓住重点,中间还能加上一些很有趣的例子 ...

  3. 浅析二分搜索树的数据结构的实现(Java 实现)

    目录 树结构简介 二分搜索树的基础知识 二叉树的基本概念 二分搜索树的基本概念 二分搜索树的基本结构代码实现 二分搜索树的常见基本操作实现 添加操作 添加操作初步实现 添加操作改进 查询操作 遍历操作 ...

  4. Hive架构原理

    什么是Hive Hive是由Facebook开源用于解决海量结构化日志的数据统计:Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射 成一张表,并提供类SQL查询功能,底层计算引 ...

  5. HDU - 1317 ~ SPFA正权回路的判断

    题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数 ...

  6. Reface.AppStarter 框架初探

    Reface.AppStarter 是一种基于 .NetFramework 的应用程序启动模式,使用该启动模式,你可以轻松的得到以下功能 : IOC / DI 自动注册与装配 简化配置 垂直模块化你的 ...

  7. session分布式处理

    session分布式处理 标签(空格分隔): 分布式 1. Session复制 在支持Session复制的Web服务器上, 通过修改服务器配置, 可以实现将Session同步到其它Web服务器上, 达 ...

  8. @Configuration和@Bean 配置类注入

    @Configuration和@Bean 1. 概述 @Configuration 注解标记在类上, 就像下面的配置文件. 我们将该类成为配置类. <?xml version="1.0 ...

  9. python:匿名函数lambda

    看个例子: a=list(map(lambda x:x*x,(1,2,3))) print(a) 输出:[1, 4, 9] lambda实际上就是匿名函数,相当于: def f(x): return ...

  10. js中的位置属性

    原生js中位置信息 clientLeft,clientTop:表示内容区域的左上角相对于整个元素左上角的位置(包括边框),实测,clientLeft=左侧边框的宽度,clientTop=顶部边框的宽度 ...