Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

the following is my code for sending email using my server.but it throws an exception.
C#
try
        {
            MailMessage Msg = new MailMessage();
            // Sender e-mail address.
            Msg.From = new MailAddress(txtEmail.Text);
            // Recipient e-mail address.
            Msg.To.Add("info@dhuvara.com");
            Msg.Subject = txtSubject.Text;
            Msg.Body = txtMessage.Text;
            Msg.IsBodyHtml = true;
            // your remote SMTP server IP.
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "mail.dhuvara.com"; 
            smtp.Port = 25;
            Msg.Priority = MailPriority.Normal;
            smtp.Credentials = new System.Net.NetworkCredential("xxxxxx", "xxxxx");
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            //Msg = null;
            lbltxt.Text = "Thanks for Contact us";
            // Clear the textbox valuess
            txtName.Text = "";
            txtSubject.Text = "";
            txtMessage.Text = "";
            txtEmail.Text = "";



and the smtp exception is : "failure to send mail"
Posted
Updated 21-Dec-13 5:46am
v2
Comments
Richard MacCutchan 21-Dec-13 11:41am    
Do you have an SMTP server running on this system? Also what is the exact value of the SmtpStatusCode that you receive?

1 solution

Hi,

Do not use:
smtp.Host = "mail.dhuvara.com";


but instead use:
smtp.Host = "smtp.live.com";


smtp.live.com is the smtp server to use for Outlook.com accounts.

Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900