0

Hi its been almost a day that I've been figuring things out with regards to sending email from godaddy email account to a gmail account. I have had my research online and almost tried everything but no luck .. here's what I made so far.

protected void generateEmail(){
        MailMessage mail = new MailMessage ();
        mail.From = new System.Net.Mail.MailAddress ("contact@company.com");
        // The important part -- configuring the SMTP client
        SmtpClient smtp = new SmtpClient ();
        smtp.Port = 465;   // [1] You can try with 465 also, I always used 587 and got success
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
        smtp.UseDefaultCredentials = false; // [3] Changed this
        smtp.Credentials = new NetworkCredential ("contact@company.com", "password123!");  // [4] Added this. Note, first parameter is Email Address of the sender and the next parameter is the password.
        smtp.Host = "relay-hosting.secureserver.net";

        //recipient address 
        mail.To.Add (new MailAddress ("test@gmail.com"));
        mail.To.Add (new MailAddress ("testagain@gmail.com"));

        //Formatted mail body 
        mail.IsBodyHtml = true;
        string st = "This is a Test  Message";

        mail.Body = st;
        smtp.Send (mail);
    } 

Can anyone help me out ? would appreciate any hands..

OneLazy
  • 459
  • 4
  • 15
  • 1
    Is there an exception detail? you can refer [Sending email in .NET through Gmail](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail?rq=1) – huoxudong125 Oct 22 '15 at 07:45
  • There is actually no exception and I dont know what I missed .. I'm actually using a GODADDY hosted email service so I cannot use smtp.gmail.com. I'm just sending email in a gmail account. – OneLazy Oct 22 '15 at 07:50
  • 1
    Did you open `exception option` for debug,to catch the exception? if you can't send mail,there must be a exception,(eg timeout etc. ) – huoxudong125 Oct 22 '15 at 07:56
  • Oh I actually have an html form where it is linked to my .aspx, so I dont see the the exception. – OneLazy Oct 22 '15 at 08:00
  • if you don't know how debug aspx. you can write the code in console appliaction and debug it.make sure the code work good,then add them to your web. – huoxudong125 Oct 22 '15 at 08:08
  • Sorry, but I dont understand.. Anyway, here's the thing, I changed my host. I tried one of my gmail accoun and used the smtp.gmail.com and it worked perfectly. It sends email. Nothing in the code I changed but only the host and the email credential. But what I really need and worry is making it possible as well in my godaddy email account. – OneLazy Oct 22 '15 at 08:12

1 Answers1

0
protected void generateEmail()
{
            //Create the msg object to be sent
            MailMessage msg = new MailMessage();

            //Add your email address to the recipients
            msg.To.Add("whereEmailWillBeSent@gmail.com");

            //Configure the address we are sending the mail from
            MailAddress address = new MailAddress("mail@company.com");
            msg.From = address;
            msg.Subject ="Hi this is mail from company";
            msg.Body = "Your Message";

            SmtpClient client = new SmtpClient();

            //for Godaddy
            client.Host = "relay-hosting.secureserver.net";
            client.Port = 25;
           client.EnableSsl = false;

            client.UseDefaultCredentials = false;

            //Send the msg
            client.Send(msg);

            //Display some feedback to the user to let them know it was sent

        }

}