Reputation: 4014
I tried to send an email using this class below, but no success, no error message, the page just executed very fast, any problem with this class?
public bool mailSender(string strSubject, string strFrom, string strFromName, string strTo, string strBody)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(strFrom, strFromName);
smtpClient.Host = ConfigurationManager.AppSettings["smtpServer"];
smtpClient.Port = 25;
smtpClient.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["smtpUsername"], ConfigurationManager.AppSettings["smtpPassword"]);
message.From = fromAddress;
message.To.Add(strTo);
message.Subject = strSubject;
message.IsBodyHtml = false;
message.Body = strBody;
smtpClient.Send(message);
return true;
}
catch
{
return false;
}
}
Upvotes: 1
Views: 1431
Reputation: 532625
One thing I have noticed, especially when running in the debugger, is that the SmtpClient doesn't seem to actually send the mail until it gets disposed. At least, I often see the messages going out when I shutdown the debugger rather than at the time the mail is actually supposed to be sent.
Upvotes: 0
Reputation: 52537
piggy backing of what bruce said, do this:
try
'your code here'
catch ex As Exception
Response.Write(ex.Message)
end try
Upvotes: 0
Reputation: 8430
Your try/catch block is deliberately throwning away any error message. Remove that and see what you get.
Upvotes: 4