我尝试从我的服务器

时间:2016-01-27 08:03:20

标签: c# asp.net email

通过localhost发送的电子邮件,但在我尝试从服务器发送时未发送。

该怎么做。

注意:我使用了port 25和host:mail.mydomain.com。

  

发送邮件失败。

你能帮我吗?

我使用过这段代码:

public static string SendMail(string host , string from , string pass , int port , string pTo, string subject, string body, string attach)
    {
        string Host = host;
        string ReceiverEmailAddres = pTo;
        string SenderEmailAddresss = from;
        string SenderEmailPassword = pass;

        SmtpClient MyMail = new SmtpClient();

        MailMessage MyMsg = new MailMessage();

        MyMail.Host = Host;

        MyMail.Port = port;
        MyMsg.To.Add(new MailAddress(ReceiverEmailAddres));
        MyMsg.Subject = subject;

        if (attach != string.Empty)
        {
            Attachment data = new Attachment(attach);
            MyMsg.Attachments.Add(data);
        }

        MyMsg.IsBodyHtml = true;
        MyMsg.From = new MailAddress(SenderEmailAddresss);

        MyMsg.Body = body;


        MyMail.UseDefaultCredentials = false;
        NetworkCredential MyCredentials = new NetworkCredential(SenderEmailAddresss, SenderEmailPassword);
        MyMail.Credentials = MyCredentials;

        try
        {
            MyMail.Send(MyMsg);
            return "ok";
        }
        catch(Exception ex)
        {
            return ex.Message;
        }
    }

1 个答案:

答案 0 :(得分:0)

检查防火墙配置是否阻止与端口25(用于发送电子邮件)的传出连接。由于缺少50个代表点,我无法首先评论并询问您是否已经尝试过这个或者您的防火墙配置是什么样的。如果您还想接收电子邮件,则应检查防火墙是否阻止与端口110(POP3)或143(IMAP4,无TLS)/ 993(IMAP4,TLS)的传入连接。