Sending Email In .NET Core 2.0

Consider the following written in .NET Core 2.0.

 1             SmtpClient client = new SmtpClient("smtp.exmail.qq.com", 587)
 2             {
 3                 UseDefaultCredentials = true,
 4                 Credentials = new NetworkCredential("[email protected]", "yHbgby"),
 5                 EnableSsl = true
 6             };
 7 
 8             MailMessage mailMessage = new MailMessage("[email protected]", "[email protected]")
 9             {
10                 Body = "<h1>body</h1>",
11                 Subject = "subject",
12                 BodyEncoding = Encoding.UTF8,
13                 IsBodyHtml = true
14             };
15 
16             client.Send(mailMessage);
17 
18             client.Dispose();
19             mailMessage.Dispose(); 

 For the most part, if you had code that could send email via SMTP in the full framework, it’s likely a matter of a copy and paste job to get it going in .NET Core now!

猜你喜欢

转载自www.cnblogs.com/kzwrcom/p/9777060.html