.netcore2.0发送邮件

时间:2024-09-26 23:35:44
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);