如何在没有凭据的情况下在.NET Core 2.1中设置我的SMTP客户端。我的邮件服务器在网络内。
private async Task<bool> SendEmailToCustomer(string customerEmail, string Message)
{
try
{
SmtpClient client = new SmtpClient(SmtpConfig.server);
if (SmtpConfig.userName != "" && SmtpConfig.password != "")
{
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(SmtpConfig.userName, SmtpConfig.password);
}
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(SmtpConfig.fromForCustomer);
mailMessage.To.Add(customerEmail);
mailMessage.Body = Message;
mailMessage.Subject = SmtpConfig.subjectForCustomer;
await client.SendMailAsync(mailMessage);
return true;
}
catch (Exception ex)
{
return false;
}
}
答案 0 :(得分:1)
没有任何变化,它很简单,无需将凭据设置为smtpclient