Using Gmail And Web Api To Send Email Failing

37349445 11 Reputation points
2021-09-06T11:32:23.097+00:00

I am currently busy with a Web Api allication that sends emails using the credentials from my gmail account. I have the following in my webconfig file

<mailSettings>
      <smtp from = "mygmailemailaddress" >
        <network host="smtp.gmail.com"
                port="587"
                userName="mygmailemailaddress"
                password="myaccountpassword"
                enableSsl="true" />
      </smtp>
    </mailSettings>

However, this keeps failing, what is the issue and how do I fix it?

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2021-09-07T02:52:43.777+00:00

    Hi @37349445 ,
    Could you post us the details of your error message?
    The reason of your problems I think there are these:

    1. Maybe the name or password isn't right. You can check whether the user name and password are correct. When sending email via code, you need to pass the full email address as the username.
    2. Maybe Gmail has blocked your application, you need to modify the settings of the less secure application and open the access to the less secure application.

    Best regards,
    Lan Huang


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments