c# - the SMTP server requires a secure connection or the client was not authenticated. The server response was 5.5.1, Authentication required -
i have been trying application send email on hour now, , i've tried i've found online still exception mentioned in title of question.
here code used:
smtpclient client = new smtpclient(); client.host = "smtp.gmail.com"; client.port = 587; client.credentials = new networkcredential("sender email", "sender email password"); client.enablessl = true; client.usedefaultcredentials = false; client.deliverymethod = smtpdeliverymethod.network; mailmessage mail = new mailmessage(); mail.from = new mailaddress("sender email", "sender"); mail.to.add(new mailaddress("my email")); mail.subject = "test"; mail.isbodyhtml = true; mail.body = sb.tostring(); client.send(mail);
i have allowed access less secure apps on account. have tried enabling 2fa , generating application specific password, exception stays.
check gmail account , turn on "acess less secure apps"
set
client.usedefaultcredentials = false;
beforeclient.credentials = new networkcredential("sender email", "sender email password");
Comments
Post a Comment