Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过本地主机发送的电子邮件,但在尝试从服务器发送时未发送_C#_Asp.net_Email - Fatal编程技术网

C# 通过本地主机发送的电子邮件,但在尝试从服务器发送时未发送

C# 通过本地主机发送的电子邮件,但在尝试从服务器发送时未发送,c#,asp.net,email,C#,Asp.net,Email,通过本地主机发送的电子邮件,但在尝试从服务器发送时未发送 怎么办 注意:我使用的是端口和主机:mail.mydomain.com 发送邮件失败 你能帮我吗 我使用了以下代码: public static string SendMail(string host , string from , string pass , int port , string pTo, string subject, string body, string attach) { string Ho

通过本地主机发送的电子邮件,但在尝试从服务器发送时未发送

怎么办

注意:我使用的是
端口和
主机: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;
        }
    }

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

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