简体   繁体   English

无法发送正文包含 IP 地址和端口号的电子邮件

[英]Failed to send an EMail with body contains ip address and port no

I have create function to send an email.我有创建功能来发送电子邮件。 This function was work successful on localhost but on server its failed without any exception.此功能在本地主机上成功运行,但在服务器上无一例外地失败。 I know the problem comes from my Port on IP Address .我知道问题来自我的Port on IP Address

The sample body is string body = "<p>Please click <a href=\\"http://123.10.10.10:9200/User/Test?userId=24c04b9e-5a32-4b7c-a61e-ea3303dac679\\">here</a></p>Thank You."示例正文是string body = "<p>Please click <a href=\\"http://123.10.10.10:9200/User/Test?userId=24c04b9e-5a32-4b7c-a61e-ea3303dac679\\">here</a></p>Thank You."

The problem is : between IP Address and Port .问题是:IP 地址端口之间。

Successful send an email if i remove : .如果我删除:成功发送电子邮件。

Do you guys have any ideas?你们有什么想法吗?

public void Sent(string sender, string receiver, string subject, string body)
    {
        using (MailMessage mail = new MailMessage(sender, receiver))
        {
            using (SmtpClient client = new SmtpClient())
            {
                client.Port = 25;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Host = "mail.companyName.com.my";
                mail.Subject = subject;
                mail.IsBodyHtml = true;
                mail.Body = body;
                client.Send(mail);
            }
        }
    }

You are doing it right, the code to send the mail is ok (you may want to revise the function name and make the smtp host name configurable, but that is not the point here).你做得对,发送邮件的代码没问题(你可能想修改函数名并使 smtp 主机名可配置,但这不是这里的重点)。

The e-mail delivery fails on a relay, there is no immedieate feedback (no exception) to the client about this kind of failure.电子邮件传递在中继上失败,没有立即向客户端反馈(也不例外)这种失败。

The best bet is the IncreaseScoreWithRedirectToOtherPort property set in Set-HostedContentFilterPolicy in case your mail provider is Office365, or a similar spam filter mechanism in any other mail provider that is encountered down the mail delivery chain.最好的办法是在Set-HostedContentFilterPolicySet-HostedContentFilterPolicy IncreaseScoreWithRedirectToOtherPort属性,以防您的邮件提供商是Office365,或者在邮件传递链中遇到的任何其他邮件提供商中的类似垃圾邮件过滤机制。

You can set a reply-to address and hope that the destination server will bounce a delivery failure that gives you more information.您可以设置一个reply-to地址,并希望目标服务器能够退回为您提供更多信息的投递失败。 Or have the admin of the mail server look up the logs.或者让邮件服务器的管理员查找日志。 More information here:更多信息在这里:
https://serverfault.com/questions/659861/office-365-exchange-online-any-way-to-block-false-url-spam https://serverfault.com/questions/659861/office-365-exchange-online-any-way-to-block-false-url-spam

Try setting the 'mail.Body' to receive a Raw Html message instead of a encoded string, like:尝试将“mail.Body”设置为接收原始 Html 消息而不是编码字符串,例如:

mail.Body = new System.Web.Mvc.HtmlHelper(new System.Web.Mvc.ViewContext(), new System.Web.Mvc.ViewPage()).Raw(body).ToString();

Or put a using System.Web.Mvc at the beginning so it gets shorter and easier to understand:或者将using System.Web.Mvc放在开头,这样它就会变得更短更容易理解:

using System.Web.Mvc

mail.Body = new HtmlHelper(new ViewContext(), new ViewPage()).Raw(body).ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM