授权SMTP在电子邮件者中
我需要在应用程序中编写一堂课,以发送电子邮件以进行授权proccess。我认为我的代码还可以,但是在汇编程序中,始终提出一个例外“ SMTP 5.7.0”。我读到,它与Google帐户中的安全设置有关,但是当我尝试更改它时,Google在官方Gmail网站上显示: “为了帮助确保您的帐户安全,从2022年5月30日起,Google不再支持使用第三方应用程序或设备,这些应用程序要求您仅使用用户名和密码登录Google帐户。”
您现在如何从应用程序中的Google帐户发送邮件?我试图将电子邮件更改为Onet,但这也不起作用。
public static class EmailSender
{
public static bool Send
(string from, string to, string subject, string name, string body, string fromPass)
{
byte[] encodedByteFrom = Encoding.Default.GetBytes(from);
from = UTF8Encoding.Default.GetString(encodedByteFrom);
byte[] encoddedByteTo = Encoding.Default.GetBytes(to);
to = UTF8Encoding.Default.GetString(encoddedByteTo);
byte[] encodedByteSubject = Encoding.Default.GetBytes(subject);
subject = UTF8Encoding.Default.GetString(encodedByteSubject);
byte[] encodedByteName = Encoding.Default.GetBytes(name);
name = UTF8Encoding.Default.GetString(encodedByteName);
byte[] encodedByteBody = Encoding.Default.GetBytes(body);
body = UTF8Encoding.Default.GetString(encodedByteBody);
byte[] encodedByteFromPass = Encoding.Default.GetBytes(fromPass);
fromPass = UTF8Encoding.Default.GetString(encodedByteFromPass);
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
message.To.Add(new MailAddress(to));
message.Subject = subject;
message.Body = body;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(from, fromPass);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(message);
return true;
}
catch (Exception ex)
{
MessageBox.Show
(ex.Message, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
return false;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个具有16个字符的应用程序密码,该密码如下所述:
然后在这里使用它:
我解决了yandex的同样问题。转到您的yandex邮件 - >所有设置 - >安全设置。然后单击应用程序密码链接。单击创建按钮并使用该密码。
如果您不必使用Gmail,则可以使用Yandex帐户尝试。因为众所周知,Gmail有一些新的安全限制。
You need to create an Application Password which has 16 characters as described here:
https://support.google.com/mail/answer/185833?hl=en-GB
Then use it here:
I solved the same problem with Yandex. Go to your Yandex Mail -> All Settings -> Security Settings. Then click App Passwords link. Click create button and use that password.
If you don't have to use Gmail you can try that with a Yandex account. Because as I know Gmail has some new security limitations.