.netcore2.0傳送郵件
阿新 • • 發佈:2018-12-25
SmtpClient smtpClient = new SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定電子郵件傳送方式 smtpClient.Host = "";//指定SMTP伺服器 smtpClient.Credentials = new NetworkCredential("", "");//使用者名稱和密碼 smtpClient.EnableSsl = true; MailAddress fromAddress= new MailAddress("fromMail", "nickName"); MailAddress toAddress = new MailAddress("toMail"); MailMessage mailMessage = new MailMessage(fromAddress, toAddress); mailMessage.Subject = "";//主題 mailMessage.Body = "";//內容 mailMessage.BodyEncoding= Encoding.Default;//正文編碼 mailMessage.IsBodyHtml = true;//設定為HTML格式 mailMessage.Priority = MailPriority.Normal;//優先順序 smtpClient.SendMailAsync(mailMessage);