简体   繁体   中英

How to send email via SMTP from my corporate gmail address using C#

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 (info@mydomain.com). I tried following steps

  1. Allow less secure apps in gmail 在此处输入图片说明
  2. Sending emails from following code

      SmtpClient client = new SmtpClient(FINAPApplicationSettings.SmtpServer, FINAPApplicationSettings.SmtpServerPort); client.UseDefaultCredentials = false; client.EnableSsl = true; client.Credentials = new NetworkCredential("info@mydomain.com", "email password"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("info@mydomain.com"); mailMessage.To.Add("receiver@receiverdomain.com"); 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. info@mydomain.com is not the admin account of g-suite. But i have the access to admin account. Your help on this is highly appreciated.

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:

  1. Enable users to manage their own settings (you've already done this)
  2. Going to (in this case) to the Google Account Page for info@mydomain.com .
  3. Clicking "Sign In and Security"
  4. Scroll to the bottom and make sure the slider is on.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM