I am trying to send an email when the app runs into an error. In this example when the app can't mapp the network drive on the computer it is running.
This is my code:
private static void MapDrive()
{
try
{
Console.WriteLine("Mapping Network Drive");
System.Diagnostics.Process.Start("net.exe", @"use w: \\server\CompanyData\W10 /user:domain\Administrator password").WaitForExit();
}
catch (Exception map)
{
Console.WriteLine(map);
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("server");
mail.From = new MailAddress("email@email.com");
mail.To.Add("user@email.com");
mail.Subject = "Machine";
mail.Body = "Could Not Map Network Drive" + System.Environment.MachineName.ToString();
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Console.ReadLine();
}
}
I think I am going the complete wrong way in doing this and need some one to point me in the right direction to get it to work.
Thanks