c# - 我无法使用 smtp 从 gmail 发送电子邮件
问题描述
无法使用 SMTP 发送电子邮件。我总是收到这个错误:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No connection could be made because the target machine actively refused it. [::ffff:74.125.140.109]:587
我在我的 Gmail 帐户中启用了安全性较低的应用程序和协议 POP 和 IMAP。
这是我的代码
using System;
using System.Net;
using System.Net.Mail;
namespace send_email
{
class Program
{
static void Main(string[] args)
{
SmtpClient clientDetails = new SmtpClient();
clientDetails.Port = 587;
clientDetails.Host = "smtp.gmail.com";
clientDetails.EnableSsl = true;
clientDetails.DeliveryMethod = SmtpDeliveryMethod.Network;
clientDetails.UseDefaultCredentials = false;
clientDetails.Credentials = new NetworkCredential("login","pasword");
MailMessage mesasge = new MailMessage();
mesasge.From = new MailAddress("app.reminder.2019@gmail.com");
mesasge.To.Add("barabas.dalibor@gmail.com");
mesasge.Subject = "Test";
mesasge.Body = "This is Test";
try
{
clientDetails.Send(mesasge);
}
catch (Exception e) {
Console.WriteLine(e);
}
Console.ReadLine();
}
}
}
我不知道我的代码是否有问题,或者我的设置是否有问题。有关如何解决此问题的任何建议?
解决方案
推荐阅读
- spring - Spring Mail - ImapIdleChannelAdapter 多次接收一些邮件,一些只接收一次
- go - 带有活动 goroutine 数量的奇怪输出
- javascript - 为什么我不能再使用 npm start 启动我的 react 应用程序了?
- node.js - 在 express js 中重构回调
- angular9 - 如何知道 Angular 页面在初始创建后何时呈现
- node.js - nodejs:sqlite3 如何更新或编辑 json 中的 json
- c++ - c ++将protobuf增量写入文件
- javascript - Why does this asynchronous function return undefined?
- c++ - Win api: HEAP_NO_SERIALIZE
- reactjs - reactstrap Collapse 没有出现在手机上