11
Answers

Unable to Send Emails after hosting the Website

mahesh munna

mahesh munna

11y
1.2k
1
Hi,


I am able to send email from a web page to the users in LOCAL HOST . But after hosting my website unable to send the mail.
Following is the error:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. ha10sm40374374pbc.23 - gsmtp

public void SendMail(string ToMail, string subject, string Message)
        {
                    // Gmail Address from where you send the mail
            string fromAddress = "[email protected]";
                    // any address where the email will be sending
            //string toAddress = ToMail;
                    //Password of your gmail address
             const string fromPassword = "********";
                     // Passing the values and make a email formate to display
            //string subject = subject;
             string body = "\n\n"+Message;
                     // smtp settings
                    var smtp = new System.Net.Mail.SmtpClient();
                    {
                        smtp.Host = "smtp.gmail.com";
                        smtp.Port = 587;
                        smtp.EnableSsl = true;
                        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                        smtp.Timeout = 20000;

                    }
                    // Passing values to smtp object
                     smtp.Send(fromAddress, ToMail, subject, body);


         }
Help me in solving this...
Answers (11)