views:

57

answers:

2

Please I had code to send emails to user when register on our website I did the code but no message was sent and error appeared (failure sending email). Please anyone help me ASAP.

bool SendMail(string account, string password, string to, string subject, string message)
{
    try
    {
        NetworkCredential loginInfo = new NetworkCredential(elarabyAccount, password);
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(account);
        msg.To.Add(new MailAddress(to));
        msg.Subject = subject;
        msg.Body = message;
        msg.IsBodyHtml = true;
        SmtpClient client = new SmtpClient("mail.example.com", 8080);
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.Credentials = loginInfo;
        client.Send(msg);

        return true;
    }
    catch (Exception)
    {
        return false;
    }
}

void BtnSend_Click(object sender, EventArgs e)
{
    SendMail("[email protected]", "xxxxx", TxtEmail.Text, "Hi", "Hi");
}
+2  A: 

you have the port set as 8080. try 25

Chris
+1  A: 

I would suspect it is simply down to the Port number. For trying to find problems like this in the future though, you should try and see what the error messages you get from a Try - Catch statement

try
{
   //code in here
}
catch (System.Net.Mail.SmtpException exsmtp)
{
    throw new Exception(exsmtp.ToString());
} 
catch (Exception ex)
{
   throw new Exception(ex.ToString());
}

You will get a lot of use(less) information from this :)

Tim B James