C# Email sending error on Godaddy server

后端 未结 3 1830
遥遥无期
遥遥无期 2021-01-22 02:39

I have one web application which hosted on Godaddy server. I am stuck with Failure sending mail error. I place my code here

public void Mailing()
{
 MailMess         


        
相关标签:
3条回答
  • 2021-01-22 03:13

    I faced the same problem when I say my previous C# working code (that was sending emails using Godaddy server) wasn't sending emails anymore. So I spend 5 hours to find the actual problem

    The problem is that Godaddy changed the settings on their servers. Due to this you won't be able to send email using:

    1. "smtpout.secureserver.net" host.
    2. local host (local system).

    I solved this by doing 2 things:

    1. Used SmtpClient Host as "relay-hosting.secureserver.net".

    2. Put my web page on my Godaddy shared server (as localhost will still not able to send smtp email due to security added by Godaddy).

    This is the correct working code from my side:

    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress("test@yourdomain.com");
    mailMessage.To.Add(new MailAddress("senderemail@gmail.com"));
    
    mailMessage.Subject = "hello";
    mailMessage.IsBodyHtml = true;
    mailMessage.Body = "hello how are you";
    
    SmtpClient client = new SmtpClient();
    client.Credentials = new System.Net.NetworkCredential("test@yourdomain.com", "yourpassword");
    client.Host = "relay-hosting.secureserver.net";
    client.Send(mailMessage);
    

    In the above code see how I added the host:

    client.Host = "relay-hosting.secureserver.net";
    

    The mail will reach you in 25 to 30 seconds time. If you still can't find the email kindly check your spam folder.

    Proof

    At the time of writing this answer I tested my code and found the send email to my Gmail Inbox. See the below image as a proof:

    0 讨论(0)
  • 2021-01-22 03:13

    Check the code below. You have to change client.Host = "smtpout.secureserver.net."

    MailMessage msg = new MailMessage(txtemail.Text, "shopover@vibrantinfosystems.com");
    msg.Subject = "Contact Us";
    string body = "Name: " + txtname.Text.Trim() + "";
    body += "<br />Email:" + txtemail.Text + "";
    body += "<br /><br /> Subject :" + txtsubject.Text + "";
    body += "<br /><br />Message : " + txtmessage.Text + "";
    msg.Body = body;
    
    msg.IsBodyHtml = true;
    
    SmtpClient client = new SmtpClient();
    client.Host = "smtpout.secureserver.net.";
    
    client.Send(msg);
    client.Timeout = 10000;
    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Mail Sent Successfully!!');", true);
    
    0 讨论(0)
  • 2021-01-22 03:15

    EnableSsl should be true. If you need a timeout then its property should be set before the email is sent try adjusting like this

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Host = "relay-hosting.secureserver.net";
    smtpClient.Port = 465;
    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = 
              new NetworkCredential("mailadress@server.net", "Password");
    
    ...
    smtpClient.Timeout = 10000;
    smtpClient.Send(message);
    
    0 讨论(0)
提交回复
热议问题