using System.Net; using System.Net.Mail; namespace OASystem.API.OAMethodLib.HotmailEmail { /// /// Hotemail 服务 /// public class HotmailEmailService { private readonly string _hotmailEmail = "your-email@hotmail.com"; private readonly string _appPassword = "your-app-specific-password"; // 不是你的登录密码,是应用专用密码 public async Task SendEmailAsync(string targetEmail, string subject, string body) { using (var client = new SmtpClient("smtp.office365.com", 587)) { client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(_hotmailEmail, _appPassword); var mailMessage = new MailMessage { From = new MailAddress(_hotmailEmail, "商邀联络官"), Subject = subject, Body = body, IsBodyHtml = true // 如果内容是 HTML 格式 }; mailMessage.To.Add(targetEmail); try { await client.SendMailAsync(mailMessage); } catch (Exception ex) { // 记录日志:ex.Message throw; } } } } }