Forum guidelines
Suresh Babu
mail was not sent after hosting the aplication
Posted By Suresh Babu on 14 Sep 2013
plese help me

i had developed a web application.. in my application i need to sent a mail to customer.. if i run my application in local system its the mail was sent successfully. but after hosting the application  the mail was not sent
this is my code
SmtpClient client = new SmtpClient();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.Host = "";
            client.Port = 587;

            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential("", "suresh57");
            client.UseDefaultCredentials = false;
            client.Credentials = credentials;

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("");
            msg.To.Add(new MailAddress(to));

            string BccAddress = "";

            msg.Subject = subject;
            msg.Body = body;

                res = true;
            catch (Exception ex)

Re: mail was not sent after hosting the aplication
Posted By Sanjeeb Lenka on 14 Sep 2013  

your code looks correct. may be your mail going to spam or junk folder check that.
Also check by changing port no 587 to 25. it may help you.

"If you Dream it You can do it"
Re: mail was not sent after hosting the aplication
Posted By Suthish Nair on 17 Sep 2013  
Port 587 and 25, both are meant for different server's. Do not mix up both. Also, check any exception you getting from try catch. Write the exception to Event Log entry and check. Also, did SMTP configured on your server, also you must setup GMAIL SMTP configuration.
Answer helped you, Mark as Answer?
C# Corner Annual Conference 2016


Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.