在.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>
Send Email in .NET Core 2.0
原文地址:http://www.cnblogs.com/bidianqing/p/7875491.html