0

This question might be flagged as a duplicate But it is not. Because the code sends email successfully when using normal gmail account that ends with @gmail.com. The problem only happens when using G suit accounts that are custom and ends with @yourdomainname.com.

I am using this code to send email. My account has two-step verification so I created an app password for verification and use it to send email.

using (var mm = new MailMessage(PrivateSettings.SenderEmail, message.Destination))
        {
            mm.Subject = message.Subject;
            mm.Body = message.Body;
            mm.IsBodyHtml = true;
            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                EnableSsl = true
            };
            var networkCred = new NetworkCredential(PrivateSettings.SenderEmail, PrivateSettings.EmailPassword);
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = networkCred;                
            smtp.Port = 587;                
            smtp.Send(mm);       
        }

The above code sends email successfully when I use my normal gmail account which is se.natnael.zeleke@gmail.com.

But when I use one of my G Suit account , connect@tatarri.com , to send email it fails and shows this error message.

enter image description here

So my question is; is their additional configuration that should be done for G suit gmail accounts.

Additional Info.

I configured both email accounts to use app password. connect@tatarri.com is also registered as admin in my G suit account.

Both email accounts have their IMAP enabled in settings.

I bought tatarri.com domain name from namecheap.

Thank you.

1 Answers1

0

The line:

smtp.UseDefaultCredentials = true;

Tells the SMTP client to use the default credentials of the currently logged in user. This is what you would use for a client application.

In your case, you want to specify credentials other than the current user's, so set it to false:

smtp.UseDefaultCredentials = false;
Fenton
  • 241,084
  • 71
  • 387
  • 401
  • the code works fine the problem only happens when i use a different "from account". When using a normal gmail account like ***@gmail.com it works but it fails when using G suit account like ***@yourdomainname.com. – natnael zeleke Jan 17 '18 at 11:56