Reputation: 1899
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).
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");
}
Upvotes: 1
Views: 907
Reputation: 20364
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 :)
Upvotes: 1