c#ASP.Net Mail-Error“无法连接到远程服务器”

时间:2018-02-24 18:47:47

标签: c# asp.net email server

private void MailGonder(string to, string from, string password, string subject, string body, HttpPostedFile ektekidosya)
{
    using (MailMessage mm = new MailMessage(from, to))
    {
        mm.Subject = subject;

        mm.Body = body;

        mm.IsBodyHtml = false;

        SmtpClient smtp = new SmtpClient();

        smtp.Host = "smtp.gmail.com";

        smtp.EnableSsl = true;

        NetworkCredential NetworkCred = new NetworkCredential(from, password);

        smtp.UseDefaultCredentials = false;

        smtp.Credentials = NetworkCred;

        smtp.Port = 587;

        smtp.Send(mm);
    }
}
    protected void BtnGonder_Click(object sender, EventArgs e)
    {
        string to = txtKime.Text;

        string from = txtEmail.Text;

        string password = txtPassword.Text;

        string subject = txtKonu.Text;

        string body = txtMesaj.Text;

        HttpPostedFile ektekidosya = fuAttach.PostedFile;

        try
        {
            MailGonder(to, from, password, subject, body, ektekidosya);
            Response.Write("Mail başarıyla gönderildi");
        }
        catch (Exception ex)
        {
            Response.Write("Mail gönderiminde hata oluştu. Err: " + ex.ToString());
        }
    }

我尝试了不同的端口,但没有任何帮助,我一直得到错误.Localserver工作正常,但服务器没有工作。我该如何解决这个错误? 我尝试了一切..我的主机是1und1。

Here Picture from my Website Error

1 个答案:

答案 0 :(得分:0)

使用gmail确保允许访问不太安全的应用

Check here Let less secure apps use your account