简体   繁体   中英

Error:Failure sending mail in asp.net

i have a problem for sending email i enter valid email but when ai click submit button i get this error, Error: Failure sending mail

here is my code(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>

and this is my code

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);
        }

    }

}

please insert this in 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>

set enableSsl to false.

Its possible you have wrong settings.

pls try enableSsl="false"

try please instead of the host "mail.Sohasys.com" put the ip address of the smtp in the web.config.

and why you mention gmail specific port ... if you use gmail smtp why you using "mail.Sohasys.com" use google instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM