"c# smtpclient class not able to send email using gmail" Code Answer


you won't belive what fixed my problem.

the credentials property

ss.credentials = new networkcredential("username", "pass");

must be declared after

ss.usedefaultcredentials = false;

so the final working code listing is

smtpclient ss = new smtpclient("smtp.gmail.com", 587);
ss.enablessl = true;
ss.timeout = 10000;
ss.deliverymethod = smtpdeliverymethod.network;
ss.usedefaultcredentials = false;
ss.credentials = new networkcredential("username", "pass");

mailmessage mm = new mailmessage("donotreply@domain.com", "destination@domain.com", "subject here", "my body");
mm.bodyencoding = utf8encoding.utf8;
mm.deliverynotificationoptions = deliverynotificationoptions.onfailure;

is this a bug?

By DeadAlready on January 17 2022

Answers related to “c# smtpclient class not able to send email using gmail”

Only authorized users can answer the Search term. Please sign in first, or register a free account.