Как настроить мой SMTP-клиент в .NET Core 2.1 без учетных данных.Мой почтовый сервер находится в сети.
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;
}
}