Hi,
How you ping your server, it is working.
Try the function below. It's fine.
The code is very similar with your code, but I don't use some property that you use.
I use it on all projects in my work.
public static string SendEmail(string strFrom, string strTo, string strCc, string strBcc, string strSubject, string strBody, string strAttach)
{
string strResults = "";
MailMessage objEmail = null;
SmtpClient objSmtp;
try
{
objEmail = new MailMessage();
objEmail.From = new MailAddress(strFrom);
objEmail.To.Add(strTo.Replace(";", ","));
if (strBcc != "")
objEmail.Bcc.Add(strBcc.Replace(";", ","));
objEmail.Priority = MailPriority.Normal;
objEmail.IsBodyHtml = true;
objEmail.Subject = strSubject;
objEmail.Body = strBody;
objEmail.SubjectEncoding = Encoding.GetEncoding("ISO-8859-1");
objEmail.BodyEncoding = Encoding.GetEncoding("ISO-8859-1");
if (strAttach != "")
{
Attachment objitemfile = new Attachment(strAttach);
objEmail.Attachments.Add(objitemfile);
}
objSmtp = new SmtpClient();
objSmtp.Host = "myserveremail@domain.com";
objSmtp.Send(objEmail);
strResults = "OK";
}
catch (System.Exception erro)
{
strResults = " 1ª - HelpLink ==> " + erro.HelpLink;
strResults += "\n\n 2ª - InnerException = " + erro.InnerException;
strResults += "\n\n 3ª - Message = " + erro.Message;
strResults += "\n\n 4ª - Source = " + erro.Source;
strResults += "\n\n 5ª - StackTrace = " + erro.StackTrace;
strResults += "\n\n 6ª - TargetSite = " + erro.TargetSite;
}
finally
{
objSmtp = null;
objEmail.Dispose();
}
return strResults;
}