Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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# 发送电子邮件与我的smtp服务器不兼容_C#_Asp.net - Fatal编程技术网

C# 发送电子邮件与我的smtp服务器不兼容

C# 发送电子邮件与我的smtp服务器不兼容,c#,asp.net,C#,Asp.net,以下是我使用smtp服务器发送电子邮件的代码。但它会抛出一个smtpexception作为发送失败 我正在为我的网站使用windows Web服务器 protected void btnSubmit_Click(object sender, EventArgs e) { try { MailMessage Msg = new MailMessage(); // Sender e-mail address. Msg.From = ne

以下是我使用smtp服务器发送电子邮件的代码。但它会抛出一个smtpexception作为发送失败

我正在为我的网站使用windows Web服务器

protected void btnSubmit_Click(object sender, EventArgs e)
{
    try
    {
        MailMessage Msg = new MailMessage();
        // Sender e-mail address.
        Msg.From = new MailAddress(txtEmail.Text);
        // Recipient e-mail address.
        Msg.To.Add("info@dhuvara.com");
        Msg.Subject = txtSubject.Text;
        Msg.Body = txtMessage.Text;
        Msg.IsBodyHtml = true;
        // your remote SMTP server IP.
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "mail.dhuvara.com"; 
        smtp.Port = 25;
        Msg.Priority = MailPriority.Normal;
        smtp.Credentials = new System.Net.NetworkCredential("info@dhuvara.com", "SolaiMail");
        smtp.EnableSsl = true;
        smtp.Send(Msg);
        //Msg = null;
        lbltxt.Text = "Thanks for Contact us";
        // Clear the textbox valuess
        txtName.Text = "";
        txtSubject.Text = "";
        txtMessage.Text = "";
        txtEmail.Text = "";
    }
    catch (Exception ex)
    {
        Console.WriteLine("{0} Exception caught.", ex);
    }

}

您需要添加smtp.UseDefaultCredentials=false


在设置凭据之前,需要先设置它。

尝试设置EnableSSL=false


这可能是问题所在——我以前遇到过这个问题

我怀疑mail.dhuvara.com是否是连接的正确主机。
此主机的DNS查找告诉我,它是go.domains.live.com的CNAME,而go.domains.live.com是domains.live.com的CNAME,因此我假设您正在使用windows live托管您的域。也许您应该尝试使用smtp.live.com作为邮件服务器。

异常包含的内容多于类名。消息是什么?你能粘贴异常消息吗?“发送邮件失败”。这是我代码中的异常消息。你确定你提供的用户帐户具有通过SMTP发送电子邮件的权限吗?我也尝试了此操作。但仍然发生相同的错误。请查看我的代码。张贴文本框的值。用它们的值替换所有txt。让我们看看整个异常。请使用ex.ToString()而不是在邮件中使用ex。这将转储堆栈和所有详细信息。