Reputation: 307
Sending emails from a personal gmail address using C# is a very common question. There are hundreds of threads available regarding this in the internet. My problem is sending emails from my g-suite account ([email protected]). I tried following steps
Sending emails from following code
SmtpClient client = new SmtpClient(FINAPApplicationSettings.SmtpServer, FINAPApplicationSettings.SmtpServerPort);
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("[email protected]", "email password");
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]");
mailMessage.To.Add("[email protected]");
mailMessage.IsBodyHtml = true;
mailMessage.Body = "Email Body";
mailMessage.Subject = "FINAP REGISTRATION VERIFICATION";
I receive this exception when try to send emails. "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" I purchased this domain (mydomain.com) from azure. [email protected] is not the admin account of g-suite. But i have the access to admin account. Your help on this is highly appreciated.
Upvotes: 1
Views: 1310
Reputation: 1260
I just tested with your code on my company G-Suite account.
After allowing users to manage their own settings, you need to make sure that the username provided in the NetworkCredential
object has been configured to "Allow less secure apps". You can get to it by:
[email protected]
. The first step may take some time to propagate to all users in G-Suite.
Note: You will also get this error if the password or username are incorrect.
If you've done all of the above and it still doesn't work, you may need to configure SPF in your DNS settings. See Authorize email senders with SPF.
Upvotes: 2