【问题标题】:aws simple email service not working with godaddy hosting asp.netaws 简单的电子邮件服务不适用于 godaddy 托管 asp.net
【发布时间】:2021-09-14 13:36:22
【问题描述】:

我之前使用 godaddy 电子邮件服务从我在 asp.net 中的 Web 应用程序发送电子邮件。但现在我转向了 aws ses,因为它很快。

事情是在开发环境(本地)aws电子邮件工作正常并且电子邮件正在发送,但是当我将它部署在godaddy服务器中时,没有电子邮件发送。我需要在 Godaddy 服务器级别进行任何设置还是我的代码错误?我的网站处于共享托管环境中。是不是这个原因。

这与 MX 记录有关吗?

这是我的代码

        string UserName = ConfigurationManager.AppSettings["UserName"];
        string EmailFrom = ConfigurationManager.AppSettings["EmailFrom"];
        string EmailFromDisplayName = ConfigurationManager.AppSettings["EmailFromDisplayName"];
        string EmailFromPwd = ConfigurationManager.AppSettings["EmailFromPwd"];
        string EmailBcc = ConfigurationManager.AppSettings["EmailBcc"];
        bool EmailIsSSL = Convert.ToBoolean(ConfigurationManager.AppSettings["EmailIsSSL"]);
        int EmailPort = Convert.ToInt32(ConfigurationManager.AppSettings["EmailPort"]);
        string EmailHost = ConfigurationManager.AppSettings["EmailHost"];

        //Create the msg object to be sent
        MailMessage mailMessage = new MailMessage();
        //Default email message 
        mailMessage.Bcc.Add(EmailBcc);
       


        //Configure the address we are sending the mail from
        MailAddress address = new MailAddress(EmailFrom, EmailFromDisplayName);
        mailMessage.From = address;

        //Loop all to recepients
        foreach(string emailTo in toAddress)
        {
            mailMessage.To.Add(emailTo);
        }
        //Loop to add all Bcc addresses...
        foreach (string emailBcc in bccAddress)
        {
            mailMessage.Bcc.Add(emailBcc);
        }
        //Loop to add all CC addresses...
        foreach (string emailCc in ccAddress)
        {
            mailMessage.CC.Add(emailCc);
        }
        //Add attachments...
        foreach (string filePathWithName in relativeFilePathsToBeAttached)
        {
            if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(filePathWithName)))
            {
                Attachment data = new Attachment(
                   System.Web.HttpContext.Current.Server.MapPath(filePathWithName),
                   MediaTypeNames.Application.Octet);
                // your path may look like Server.MapPath("~/file.ABC")
                mailMessage.Attachments.Add(data);
            }
        }

        mailMessage.Subject = mailSubject;
        mailMessage.Body = mailBody;
        mailMessage.IsBodyHtml = IsBodyHtml;

        //Configure an SmtpClient to send the mail.
        SmtpClient client = new SmtpClient();
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.EnableSsl = EmailIsSSL;
        client.Host = EmailHost;
        client.Port = EmailPort;

        //Setup credentials to login to our sender email address ("UserName", "Password")
        //NetworkCredential credentials = new NetworkCredential(EmailFrom, EmailFromPwd);

        NetworkCredential credentials = new NetworkCredential(UserName, EmailFromPwd);

        client.UseDefaultCredentials = true;
        client.Credentials = credentials;
        
        if (ConfigurationManager.AppSettings["IsMailEnabled"].ToString() == "true")
        {
            client.Send(mailMessage);
        }

我在服务器上收到此错误 发送 mail.System.IO.IOException 失败:无法从传输连接读取数据:net_io_connectionclosed。在 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) at System.Net.Mail.SmtpClient.Send(MailMessage message) at TestCookie.ExecuteSendEmail(String mailBody, String mailSubject, List1 toAddress, List1 bccAddress, List1 ccAddress, List1 relativeFilePathsToBeAttached, Boolean IsBodyHtml)

【问题讨论】:

  • “没有电子邮件发送”是什么意思?你的代码能运行吗?您是否在附加调试器的情况下运行它?是否抛出异常?是否启用邮件?
  • 在本地这工作正常并从这里发送电子邮件 client.Send(mailMessage);。但部署后不起作用。是的代码适用于本地
  • 请重新阅读我的评论。我没有问任何关于本地与非本地的问题。我问了一些非常具体的问题。请花时间回答他们。
  • “没有电子邮件发送”是什么意思?电子邮件不工作/发送您的代码是否运行?是的。您是否在附加调试器的情况下运行它?是的。是否抛出异常?不。IsMailEnabled?是的
  • 如果 SMTP 客户端没有抛出异常,并且您确定它已经到达,那么邮件服务器就会出现问题。您必须查看日志才能找到它。

标签: asp.net amazon-ses godaddy-api


【解决方案1】:

问题出在端口号上。我使用的是 587 和 25,但它不起作用。但是当我使用 2587 并且它对我有用时。我不知道怎么做。如果有人可以解释,那将有所帮助。

【讨论】:

    猜你喜欢
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    相关资源
    最近更新 更多