.net - SmtpClinet(SmarterEmail 服务器)的 SMTP 发送电子邮件失败

标签 .net email configuration smtp admin

我已经配置并运行 SmarterEmail 服务器,为 25 端口运行 SMTP 服务,配置电子邮件帐户。

我创建了简单的 .NET 应用程序来通过我的电子邮件服务器发送电子邮件,它真的很简单:

        public void SendEmail(EmailMessage message, string username, string password, string host, int port, bool enableSsl)
    {
        MailMessage mm = new MailMessage(message.From, message.To, message.Subject, message.Message);
        NetworkCredential credentials = new NetworkCredential(username, password);

        SmtpClient sc = new SmtpClient(host, 25);
        sc.DeliveryMethod = SmtpDeliveryMethod.Network;
        sc.UseDefaultCredentials = false;
        sc.EnableSsl = enableSsl;
        sc.Credentials = credentials;

        sc.Send(mm);
    }

此应用程序失败,异常:

Unhandled Exception: System.Net.Mail.SmtpException: Failure sending mail. ---> S ystem.Net.WebException: Unable to connect to the remote server ---> System.Net.S ockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection faile d because connected host has failed to respond 173.248.182.102:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre ss socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object ow ner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket 6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncD elegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at SendMail.MailService.SendEmail(EmailMessage message, String username, Stri ng password, String host, Int32 port, Boolean enableSsl) in D:\Development\Proje cts\Experiments\SendMail\SendMail\Program.cs:line 36 at SendMail.Program.Main(String[] args) in D:\Development\Projects\Experiment s\SendMail\SendMail\Program.cs:line 52



邮件服务器:mail.trackyt.net,端口 = 25,SSL = false。它在我的(本地)机器上不起作用。

同时,如果我将此应用程序复制到运行 SmarterEmail(远程)的机器,它会成功运行!

我认为它被防火墙阻止,在远程机器上启用了 25 - 结果相同。
禁用本地和远程计算机的防火墙 - 结果相同。

附加诊断:

通过 http://pingability.com/smtptest.jsp 运行 SMTP 测试:

EHLO pingability.com 250-MAST-WIN2K8R2-STD Hello [207.210.209.134] 250-SIZE 31457280 250-AUTH LOGIN CRAM-MD5 250 OK DEBUG SMTP: Found extension "SIZE", arg "31457280" DEBUG SMTP: Found extension "AUTH", arg "LOGIN CRAM-MD5" DEBUG SMTP: Found extension "OK", arg "" DEBUG SMTP: Attempt to authenticate DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM AUTH LOGIN 334 VXNlcm5hbWU6 c3VwcG9ydA== 334 UGFzc3dvcmQ6 c3VwcG9ydDEyMw== 235 Authentication successful



它说 SMTP 没问题。

从我的机器远程登录:

Microsoft Telnet> o mail.trackyt.net 25 Connecting To mail.trackyt.net...Could not open connection to the host, on port 25: Connect failed



来自 SmarterMail 机器的相同 telnet 是可以的。

有任何想法吗 ?

最佳答案

你是在家里做这个吗?许多 ISP 阻止传出端口 25。

在 smartermail 中,您可以为另一个端口添加 SMTP 监听器。尝试为 587 添加一个,看看您是否可以连接到它(假设您具有执行此操作的管理员权限)。

--戴夫

关于.net - SmtpClinet(SmarterEmail 服务器)的 SMTP 发送电子邮件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4322123/

相关文章:

Ubuntu 14.04 64 位中的 JavaFX MediaPlayer

.net - 如何在 .NET Core 上直接调用 F# 编译器?

.net - 将标识符模式与 `as` 模式相结合

c# - StringBuilder 和 JSON 的问题

.net - 使用嵌套分隔符解析字符串

email - 为什么在电子邮件中写 'at' 和 'dot' 而不是 '@' 和 '.' ?

php 从本地主机发送邮件

javascript - Google Apps 脚本 | Switch Case 仅选择默认选项

configuration - 如何为 prometheus 运算符(operator)启用其他配置

php - 是什么导致 CPU 负载如此之高(来自 MySQL)?