I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message
var fromAddres
I tried all of the suggestions found here, from enabling less secure apps, to trying port 587... nothing worked. Finally I just commented out the line UseDefaultCredentials = false
. Everything worked if I didn't touch that boolean.
You might need to create/generate a specific APP password from gmail. you app or script will then use this new password instead of your regular password. Your regular password will still work fine for you.
That is what did it for me. I still used the same email account but had to generate a new app specific password.
https://support.google.com/accounts/answer/185833?hl=en
Basically you can do it here: https://security.google.com/settings/security/apppasswords
If your are using gmail.
1-logon to your account
2- browse this link
3- Allow less secure apps: ON
Enjoy....
I have faced the same problem. It happens when you turn on 2 Step Verification (MFA). Just Turn off 2 Step Verification and your problem should be solved.
NOVEMBER 2018, have tried everything above with no success.
Below is the solution that worked finally. Unfortunately it's not using SSL, but it works!!!
var fromAddress = new MailAddress(asd@asd.com, "From Name");
var toAddress = new MailAddress("tosend@asd.com", "To Name");
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "aspmx.l.google.com",
Port = 25,
EnableSsl = false
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
dont put break-point before await smtp.SendMailAsync(mail);
:)
when it waits with a break point giving this error when i remove break point it has worked