0

我在发送电子邮件时遇到问题我输入了有效的电子邮件但是当我点击提交按钮时我收到此错误,错误:发送邮件失败

这是我的代码(web.Config)

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="Soha@sohasys.com">
        <!-- Default Port is [25] -->
        <!-- Specific Port for Gmail is [587] NOT!!! [995]-->
        <network defaultCredentials="false" host="mail.Sohasys.com" enableSsl="true" userName="Soha@sohasys.com" password="XXXX" port="587"/>
      </smtp>
    </mailSettings>
  </system.net>

这是我的代码

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        try
        {
            System.Net.Mail.MailMessage oMailMessage = new System.Net.Mail.MailMessage();

            oMailMessage.IsBodyHtml = true;
            oMailMessage.Priority = System.Net.Mail.MailPriority.Normal;
            oMailMessage.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.Never;

            System.Net.Mail.MailAddress oMailAddress = null;

            oMailAddress =
                new System.Net.Mail.MailAddress(txtEmail0.Text, ttxtPhone.Text, System.Text.Encoding.UTF8);

            oMailMessage.From = oMailAddress;
            oMailMessage.Sender = oMailAddress;
            oMailMessage.ReplyTo = oMailAddress;

            oMailAddress =
                new System.Net.Mail.MailAddress("Soha@sohasys.com", "", System.Text.Encoding.UTF8);
            oMailMessage.To.Add(oMailAddress);

            // oMailMessage.CC
            // oMailMessage.Bcc

            oMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
            oMailMessage.Subject = "(From WebSite)" + " : " + txtUsername.Text;

            oMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            oMailMessage.Body = txtBody.Text;

            System.Net.Mail.SmtpClient oSmtpClient = new System.Net.Mail.SmtpClient("Soha@sohasys.com", 587);


              oSmtpClient.EnableSsl = true;
            oSmtpClient.Timeout = 100000;

           // oSmtpClient.UseDefaultCredentials = false;

         //  ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

            oSmtpClient.Send(oMailMessage);
            Label5.Visible = true;
            Label5.Text = "Your Email Send SuccesFully.";

        }
        catch (System.Exception ex)
        {
            Response.Write("Error: " + ex.Message);
        }

    }

}
4

3 回答 3

1

请将此插入 web.config

system.net>
<mailSettings>
  <smtp deliveryMethod="Network" from="Soha@sohasys.com">
    <!-- Default Port is [25] -->
    <!-- Specific Port for Gmail is [587] NOT!!! [995]-->
    <network defaultCredentials="false" host="mail.Sohasys.com" enableSsl="false" userName="Soha@sohasys.com" password="XXXX" port="587"/>
  </smtp>
</mailSettings>

将 enableSsl 设置为 false。

于 2015-11-06T09:16:52.460 回答
0

请尝试将 smtp 的 IP 地址代替主机“mail.Sohasys.com”放在 web.config 中。

以及为什么您提到 gmail 特定端口...如果您使用 gmail smtp 为什么您使用“mail.Sohasys.com”请使用 google

于 2012-12-17T21:45:27.487 回答
0

可能你有错误的设置。

请尝试 enableSsl="false"

于 2012-12-17T21:42:25.963 回答