且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当发送帐户使用两因素身份验证时,如何通过Gmail和SmtpClient发送电子邮件?

更新时间:2022-12-06 16:57:34

如果我正确理解您的意思,就是说Google帐户使用的是双重身份验证.

If I understand you correctly, you're saying the Google account is using two-factor authentication.

在这种情况下,您需要为此创建一个应用程序密码.登录后,请转到 https://security.google.com/settings/security/apppasswords 作为您要进行双重身份验证的帐户.

If that's the case, you need to create an Application Password for this. Go to https://security.google.com/settings/security/apppasswords once logged in as the account you want to two-factor auth with.

在列表的 Select App 下,选择"Other"并为其命名.单击生成",然后将此密码写为"DOWN",因为您只会一次看到该密码.您将在身份验证中使用它.长度为16个字符,空格无关紧要,您可以包含它们,也可以忽略它们.我之所以把它们包括在这里是因为.

In the list, under Select App choose "Other" and give it some name. Click Generate, and write this password DOWN cause you will only ever see it ONCE. You will use this in your authentication. It will be 16-characters long and the spaces don't matter, you can include them or omit them. I included them here just because.

NetworkCredential basicCredential =
            new NetworkCredential("sender@gmail.com", "cadf afal rqcf cafo");
MailMessage message = new MailMessage();