Send Email in .NET Core 2.0

在.NET Core 1.0 中,SMTP Client代码并没有被移植,直到.NET Core 2.0的发布。使用下面的代码:

static void Main(string[] args)
{
    SmtpClient client = new SmtpClient("smtp.163.com");
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential("bidianqing123", "your password");

    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress("bidianqing123@163.com");
    mailMessage.To.Add("bidianqing@qq.com");
    mailMessage.Body = "body";
    mailMessage.Subject = "subject";
    client.Send(mailMessage);
    Console.WriteLine("发送成功");
    Console.ReadKey();
}

一定要确保框架是.NET Core 2.0,否则你将无法使用它。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>
上一篇:【MM系列】SAP MM模块-组织结构介绍


下一篇:FAT32文件系统的存储组织结构(一)