I'm trying to send an email with the MailKit. However, it was working before and now suddenly is not working anymore. I'm able to connect & authenticate but when it reaches the send email, is throwing an error.
Error code: MessageNotAccepted
Error message: 6.6.0 Error sending message for delivery.
Here is my code
var message = new MimeMessage();
message.From.Add(new MailboxAddress(contactModel.Name, "ssssss@yahoo.com"));
// This needs to be put in a configuration file
message.To.Add(new MailboxAddress("NorbertDev", "sssssss@gmail.com"));
message.Subject = $"{contactModel.Name} contacted me!";
message.Body = new TextPart("plain") {
Text = contactModel.Message +
" Details of sender: " + contactModel.EmailAddress + ", " + contactModel.ContactNumber + " ," + contactModel.Name
};
using (var client = new SmtpClient())
{
try
{
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12 |
System.Security.Authentication.SslProtocols.Tls |
System.Security.Authentication.SslProtocols.Ssl3 |
System.Security.Authentication.SslProtocols.Ssl2;
if (!client.IsConnected)
{
await client.ConnectAsync("smtp.mail.yahoo.com", 587, false).ConfigureAwait(false);
}
if (!client.IsAuthenticated)
{
await client.AuthenticateAsync("ssssss@yahoo.com", "aaaaaaaaaaa").ConfigureAwait(false);
}
await client.SendAsync(message).ConfigureAwait(false); <-- Here is the error
await client.DisconnectAsync(true).ConfigureAwait(false);
return "success";
}
catch (Exception e)
{
throw new Exception($"The email from {contactModel.EmailAddress} captured but not sent to the owner");
}
}