Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我不能用smtp从gmail发送电子邮件_C#_Email_Gmail_Visual Studio 2019 - Fatal编程技术网

C# 我不能用smtp从gmail发送电子邮件

C# 我不能用smtp从gmail发送电子邮件,c#,email,gmail,visual-studio-2019,C#,Email,Gmail,Visual Studio 2019,无法使用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.1

无法使用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();
        }
    }
}

我不知道我的代码是否有问题,或者设置是否有问题。有关如何修复此问题的任何建议?

您使用的是什么版本的.Net Framework?您是否能够通过本地SMTP服务器发送邮件?你会被防火墙阻止吗?它通常是有效的。改用端口25试试。请注意,SmtpClient已过时/不推荐使用。你可以在文档中。我创建了控制台应用程序(.net core),我是否必须使用(.net Framework)?如果不以框架为目标,你不能做任何事情(它在项目属性中)。选择最近的一个。