Sending mail RRS feed

  • Question

  • Hi , 

    I have received unable to connect remote server error while sending mail using asp.net 

    I am using private server to send the mail, 

    could you suggest any idea 

    here my code 


         private static void SendMail()

                    string SmtpHost = ConfigurationManager.AppSettings["SmtpHost"].ToString();
                    string SmtpFromMail = ConfigurationManager.AppSettings["SmtpFromMail"].ToString();
                    string SmtpFromMailPwd = ConfigurationManager.AppSettings["SmtpFromMailPwd"].ToString();               
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(SmtpFromMail);               
                    mail.Body = "Test";               
                    mail.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = SmtpHost;
                    smtp.Port = 25;             
                    smtp.Credentials = new System.Net.NetworkCredential(SmtpFromMail, SmtpFromMailPwd); // **use valid credentials**              
                    smtp.EnableSsl = false;
                }catch(Exception e)


    Thanks in advance !

    Wednesday, November 14, 2018 6:44 AM

All replies

  • The obvious question is, have you printed out the SmtpHost name to make sure you're actually getting the right host?  Are you quite sure you should be using port 25?  That's unencrypted, which means you're sending your credentials in plain text.  Can you use telnet to connect to port 25 from your ASP host?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, November 14, 2018 7:21 AM
  • I guess the problem with the credentials which you are using to connect your smtp server. Please check your smtp server credentials to send mail in c#.

    Check following articles to send mail using asp.net in c#.




    Wednesday, November 14, 2018 8:30 AM
  • If you may get more information by subscribing to SendCompleted.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, November 14, 2018 10:31 AM
  • Hi Jebin_Dhanush,

    Thank you for posting here.

    For your question, please change EnableSsl to true.


     smtp.EnableSsl = false;


                smtp.EnableSsl = true;

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Tuesday, December 4, 2018 8:25 AM
    Thursday, November 15, 2018 8:07 AM