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

发布于 2024-10-04 23:35:06 字数 3316 浏览 6 评论 0原文

我已经配置并运行 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);
    }

此应用程序失败,但出现异常:

未处理的异常:System.Net.Mail.SmtpException:发送邮件失败。 ---> S ystem.Net.WebException:无法连接到远程服务器--->系统.Net.S ockets.SocketException:连接尝试失败,因为连接方 一段时间后没有正确响应,或建立连接失败 d 因为连接的主机未能响应 173.248.182.102:25 在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre ss 套接字地址) 在 System.Net.ServicePoint.ConnectSocketInternal(布尔 connectFailure,Sock et s4、Socket s6、Socket&套接字、IP地址&地址、ConnectSocketState 状态、 IAsyncResult asyncResult、Int32超时、Exception&例外) --- 内部异常堆栈跟踪结束 --- 在 System.Net.ServicePoint.GetConnection(PooledStream PooledStream,对象流 ner、布尔异步、IPAddress&地址、套接字和abortSocket、Socket&中止套接字 6、Int32超时) 在 System.Net.PooledStream.Activate(对象 owningObject,布尔异步,Int32 超时、GeneralAsyncDelegate asyncCallback) 在 System.Net.PooledStream.Activate(对象 owningObject,GeneralAsyncDelegate 异步回调) 在 System.Net.ConnectionPool.GetConnection(对象 owningObject,GeneralAsyncD elegate asyncCallback,Int32 创建超时) 在 System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) 在 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) 在 System.Net.Mail.SmtpClient.GetConnection() 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息) 在 SendMail.MailService.SendEmail(EmailMessage 消息,字符串用户名,Stri D:\Development\Proje 中的 ng 密码、字符串主机、Int32 端口、布尔值 enableSsl) cts\Experiments\SendMail\SendMail\Program.cs:第 36 行 位于 D:\Development\Projects\Experiment 中的 SendMail.Program.Main(String[] args) s\SendMail\SendMail\Program.cs:第 52 行

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

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

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

其他诊断:

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

EHLO pingability.com 250-MAST-WIN2K8R2-STD 你好 [207.210.209.134] 250-尺寸 31457280 250-AUTH 登录 CRAM-MD5 250 好 调试 SMTP:找到扩展名“SIZE”,arg“31457280” 调试 SMTP:找到扩展名“AUTH”,arg“LOGIN CRAM-MD5” 调试 SMTP:找到扩展名“OK”,arg“” 调试 SMTP:尝试进行身份验证 调试 SMTP:检查机制:LOGIN PLAIN DIGEST-MD5 NTLM 授权登录 第334章 c3VwcG9ydA== 第334章 c3VwcG9ydDEyMw== 235 认证成功

表示 SMTP 正常。

从我的机器远程登录:

微软远程登录> o mail.trackyt.net 25 正在连接到 mail.trackyt.net...无法在端口上打开与主机的连接 25:连接失败

从 SmarterMail 机器进行相同的 telnet 正常。

有什么想法吗?

I have configured and running SmarterEmail server, running SMTP service for 25 port, configured email account.

I've created simple .NET application to send email by my Email server, it is really simple:

        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);
    }

This application failed with exception:

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 server: mail.trackyt.net, port = 25, SSL = false. It does not work from my (local) machine.

In the same time, if I copy this application to machine were SmarterEmail (remote) is running, it successfully works!

I thought it blocked by Firewall, enabled 25 on remote machine - same result.
Disabled Firewall, both locally and remote machine - same result.

Additional diagnostic:

Run SMTP test by http://pingability.com/smtptest.jsp:

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

It says that SMTP is OK.

Telnet from my machine:

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

Same telnet from SmarterMail machine is OK.

Any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2024-10-11 23:35:06

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

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

——戴夫

Are you doing this from home? A lot of ISPs block outgoing port 25.

In smartermail you can add a SMTP listener for another port. Try adding one for 587, and see if you can connect to it (assuming you have admin rights to do this).

--dave

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文