You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET 4.8生产环境无法发送邮件问题求助

ASP.NET网站部署到Ionos服务器后SMTP发送邮件失败

我用Visual Studio创建了一个基于C#、目标框架为.NET 4.8的ASP.NET网站,部署在Ionos(原1&1)的Windows服务器上,但没有服务器或IIS控制台的访问权限。

本地开发工作站上,以下代码定义的MailSender.Send(...)可以成功发送邮件:

using System;
using System.Net;
using System.Net.Mail;

public class MailSender {
    public static void Send(string server, int port, string body, string subject, string to = "xxxxxxx@gmail.com", string from = "noreply@xxxxxxxx.com") {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        SmtpClient smtp = new SmtpClient(server, port);
        smtp.Credentials = new NetworkCredential(user, pw);
        smtp.EnableSsl = true;

        MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress(from);
        Msg.To.Add(to);
        Msg.Subject = subject;
        Msg.IsBodyHtml = true;
        Msg.Body = BuildBody(body);

        smtp.Send(Msg);
    }
}

但部署到宿主服务器后,发送邮件失败,报错如下:

System.Net.Mail.SmtpException: Failure sending mail. ---> **System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed**.
 at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
 at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
 at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
 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 MailSender.Send_New(String server, Int32 port, String body, String subject, String to, String from)

我已尝试以下方法但均未解决:

  • 当前使用端口587,尝试465、25端口结果相同;
  • 尝试多种SecurityProtocolType值,无差异;
  • 尝试System.Web.Mail、内置WebMail类等多种发送方式,结果一致;
  • 确认网站确实以.NET 4.8为目标框架;
  • 查阅谷歌及开发者论坛的相关文章,尝试多种方案无效;
  • 联系Ionos支持,对方称无服务器问题,属于开发问题无法协助。

至今已耗时两周仍未解决,恳请各位提供解决思路!

内容的提问来源于stack exchange,提问作者Sébastien Grossetti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 15:30:22