SMTP和OAuth的2 [英] SMTP and OAuth 2

查看:213
本文介绍了SMTP和OAuth的2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过OAuth协议是否.NET支持SMTP认证?基本上,我想能够发送电子邮件的用户的使用OAuth访问令牌代为。但是,我无法找到这样的支持,在.NET框架。

Does .NET support SMTP authentication via OAuth protocol? Basically, I would like to be able to send emails on users' behalves using OAuth access tokens. However, I couldn't find a support for this in the .NET framework.

谷歌提供了一些样本的这个在其他环境中,但不是.NET。

Google provides some samples for this in other environments but not .NET.

推荐答案

System.Net.Mail不支持OAuth的或OAuth2。但是,您可以使用 MailKit 的(注:只支持OAuth2)的 SmtpClient 到,只要你有用户的OAuth访问令牌(MailKit没有发送消息code,将获取的OAuth令牌,但它可以使用它,如果你有的话)。

System.Net.Mail does not support OAuth or OAuth2. However, you can use MailKit's (note: only supports OAuth2) SmtpClient to send messages as long as you have the user's OAuth access token (MailKit does not have code that will fetch the OAuth token, but it can use it if you have it).

using (var client = new SmtpClient ()) {
    client.Connect ("smtp.gmail.com", 587, SecureSocketOptions.StartTls);

    client.Authenticate (usersLoginName, usersOAuthToken);

    client.Send (message);

    client.Disconnect (true);
}

这篇关于SMTP和OAuth的2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆