在.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("[email protected]"); mailMessage.To.Add("[email protected]"); 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>
时间: 2024-10-14 05:24:03