I have a C# services checker program. The exe is kicked off from a bat file which also passes in a number of arguments (e.g an int count of how many services you want to check, string of the service display name) and also emailTo, emailFrom, emailServer, etc as if a service is not running a email will be sent. This is the code for the email part:
MailMessage mail = new MailMessage(emailFrom, emailTo);
SmtpClient SMTP = new SmtpClient(emailServer);
if (emailUser != "")
{
SMTP.Credentials = new NetworkCredential(emailUser, emailPass);
}
mail.Subject = "The " + service + " service has stopped running";
mail.Body = "Please take a look into the " +
service + " service and think about restarting.";
SMTP.Send(mail);
So on one server I use emailServer as “localhost” passed in, in the bat file and when it runs if a service that I am checking is not running then the email is sent fine and everything is working. However on a different server I again use “localhost” as my emailServer but when I run the bat file. I get an error System.Net.Mail.Smtp.Exception [8012], and the email is not sent. Is this something that is not set up on the server rather than the program that is causing my issue (server config isnt my strong area).
Thanks.
Is there an e-mail server running on the server where your program fails? You are trying to send e-mail to
localhost(i.e. the computer where your program is executed). If SMTP port 25 is not responding on that machine your e-mail will not be delivered.For
emailServeryou have to supply the host name of the computer in your network that is able to accept and handle e-mail. Normally you would not uselocalhostfor the name of that computer.