Can send emails through Gmail account only if account has "Access for less secure apps" enabled
Asked Answered
C

2

9

If my Gmail account has Access for less secure apps disabled, then my application can't send emails through this account. Instead I get "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" exception.

Here Google explains that by disabling Access for less secure apps, only apps that use modern security standards can sign in.

What are those modern security standards my code needs to implement and can you show me how to implement them with an example ( not sure if it matters, but my app and Gmail account aren't using 2-step verification )?

Here's the code I'm currently using:

public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        var credentialUserName = "[email protected]";
        var sentFrom = "[email protected]";
        var pwd = "myPwd";

        System.Net.Mail.SmtpClient client = 
            new System.Net.Mail.SmtpClient("smtp.gmail.com");

        client.Port = 587;
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        System.Net.NetworkCredential credentials = 
            new System.Net.NetworkCredential(credentialUserName, pwd);

        client.EnableSsl = true;
        client.Credentials = credentials;

        var mail = 
            new System.Net.Mail.MailMessage(sentFrom, message.Destination);

        mail.Subject = message.Subject;
        mail.Body = message.Body;

        return client.SendMailAsync(mail);
    }
}
Combo answered 25/8, 2014 at 17:18 Comment(4)
They switched over to OAuth 2.0. Anything else is "less secure" to them.Sad
Also, if you have multiple GMail accounts, and you follow the link to enable access for less secure apps from the GMail app on a mobile device, make sure you are updating the settings for the intended account. If you do not receive an e-mail stating that access for less secure apps is enabled, double-check the settings and ensure it has been applied to the intended account.Jilolo
Just about to ask this question. Thanks. +1Equanimity
If it helps, I have an old phone where, when I try accessing gmail, it say incorrect password, and later, on my PC, I get an email from Google saying "Access from a device we don't consider safe was stopped"..Duplicate
A
1

Considering that the asp.net-identity-2 tag is applied to this question, and considering that Google requires use of OAuth 2.0 to avoid having to use the Access for less secure applications option, it appears that one option is to use the OWIN middleware able to be found by searching for the term Oauth 2.0 at www.asp.net.

This site hosts an article titled Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on that might be of some interest. The article appears to show many screenshots that walk a developer through the process of getting the resource, creating an app, and authenticating with a Google server.

Advisement answered 26/5, 2016 at 18:31 Comment(0)
R
0

I think it "Less secure" only means that you are giving credentials to third party and they do not use two step verification.

About Google "Less Secure" Settings

It should be noted that Google's statement of Less Secure should not be read as Insecure. Less Secure Apps is a label describing a behavioral issue and not a technical issue. Lots of things can go wrong when you give your credentials to a third party to give to the authentication authority: the third party might keep the credentials in storage without telling you, they might use your credentials for purposes outside the stated scope of the application, they might send your credentials over a network without encryption, etc. Ultimately, it is only Less Secure if the third party in question has malicious intent and therefore you should always be vigilant in knowing who you are sending your credentials to. COMPanion Corp stores your credentials only for the purpose of utilizing Googles SMTP Email service and they are stored using the most up-to-date security.

Source: http://www.goalexandria.com/v7Docs/index.php/Using_Gmail_as_Your_SMTP_Server

Remedial answered 25/5, 2019 at 4:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.