public void UpdateData() { try { sendMail(UpdateData());//here message is success } Catch(Exception ex) { sendMail(ex.Message) } } public void sendMail(string strExceptionMsg) { MailMessage objMailMessage = null; SmtpClient SmtpMail = null; System.IO.StreamWriter Log=null; try { using ( Log Log = new System.IO.StreamWriter(apppath + "\\ImportLogMail.txt", true)) { Log.WriteLine(DateTime.Now.ToString() + "Start Sending Email......."); objMailMessage = new MailMessage(); objMailMessage.To.Add(MailTo); objMailMessage.From = new MailAddress(MailFrom); if (resultId == 0) { objMailMessage.IsBodyHtml = false; objMailMessage.Subject = "Branch Code Update Status"; if (isValidTextFile) { objMailMessage.Body = "Hi" + Environment.NewLine + "Please find the attached text file for log information."; } else { objMailMessage.Body = "The file:" + fileName + " content of the file was not correct format"; } Attachment attach = new Attachment(apppath + "\\ImportLog.txt"); objMailMessage.Attachments.Add(attach); } else { objMailMessage.IsBodyHtml = false; objMailMessage.Subject = "Branch Code Update Status -Exception"; objMailMessage.Body = "Hi" + Environment.NewLine + "The following error occured while running the project." + Environment.NewLine + strExceptionMsg; } SmtpMail = new SmtpClient(); SmtpMail.Host = SMTPHost; SmtpMail.Port = Convert.ToInt32(SMTPPort); //SmtpMail.Timeout = 50000; SmtpMail.EnableSsl = false; SmtpMail.Credentials = new System.Net.NetworkCredential(SMTPUserId, SMTPPassword); SmtpMail.UseDefaultCredentials = true; SmtpMail.Send(objMailMessage); Log.WriteLine(DateTime.Now.ToString() + "End Sending Email......."); } catch (SmtpException ex) { Log.WriteLine(ex.message); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)