static void SendMail() { string config = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + SmtpInfo.SMTP_INFO_FILE); SmtpInfo smtpInfo = SmtpInfo.Deserialize(config); SMTPTransport transport = new SMTPTransport(); transport.SendAsynchronous = false; List <string> mailTo = new List <string>(); string subject = string.Empty; string body = string.Empty; Console.WriteLine("Send Mail to :"); mailTo.Add(Console.ReadLine()); Console.WriteLine("Subject :"); subject = Console.ReadLine(); Console.WriteLine("Body :"); body = Console.ReadLine(); try { Console.WriteLine("Sending Mail..."); transport.SmtpSend(smtpInfo, mailTo, null, subject, body, null); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ReadLine(); Environment.Exit(1); } Console.WriteLine("Mail Sent"); Console.ReadLine(); Environment.Exit(1); }
public void SendMail() { configManager.Logger.Debug(EnumMethod.START); string subject = string.Format(_subject, _alertType, configManager.SystemAnalyzerInfo.ClientInstanceName, _user); SMTPTransport smtp = new SMTPTransport(); try { smtp.SendAsynchronous = true; SaveLog(); smtp.SmtpSend(configManager.SmtpInfo, configManager.SystemAnalyzerInfo.ListAlertMailSubscription, null, subject, GenerateMessageBody(), null); } catch (Exception ex) { configManager.Logger.Error(ex); } configManager.Logger.Debug(EnumMethod.END); }
/// <summary> /// Sends the mail. /// </summary> /// <param name="subject">The subject.</param> /// <param name="mailBody">The mail body.</param> /// <param name="emails">The emails.</param> /// <param name="attachments">The attachments.</param> /// <returns></returns> public static bool SendMail(string subject, string mailBody, List <string> emails, List <string> attachments) { logger.Debug(EnumMethod.START); SMTPTransport smtpTransport = new SMTPTransport(); bool success = false; try { smtpTransport.SmtpSend(configManager.SmtpInfo, emails, null, subject, mailBody, attachments); success = true; } catch (Exception ex) { success = false; logger.Error(ex); } finally { logger.Debug(EnumMethod.END); } return(success); }
//---------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Reportings the task. /// </summary> public void ReportingTask() { configManager.Logger.Debug(EnumMethod.START); if (configManager.SystemAnalyzerInfo.SetPMA) { SMTPTransport smtpTransport = new SMTPTransport(); FTPTransport ftpTransport = new FTPTransport(); try { _reportFileName = string.Empty; if (File.Exists(_fileName)) { _reportFileName = CreateAllProcessCSVReport(_fileName); } if (DateTime.Now > mailingTime) { mailingTime = mailingTime.AddHours(configManager.PMAInfoObj.ReportsIntervalHours); configManager.PMAInfoObj.MailingTime = mailingTime; } if (File.Exists(_fileName)) { if (configManager.PMAInfoObj.UseSMTP) { try { string subject = "PMA System Alerts : PMA Report : " + configManager.SystemAnalyzerInfo.ClientInstanceName + " : " + Environment.MachineName + " : " + " at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); List<string> attachments = new List<string>(); attachments.Add(_reportFileName); smtpTransport.SmtpSend(configManager.SmtpInfo, configManager.SystemAnalyzerInfo.ListPMAReportSubscription, null, subject, GenerateMailMessageBody(), attachments); } catch (InvalidOperationException ex) { configManager.Logger.Message(ex.Message); } catch (Exception ex) { configManager.Logger.Error(ex); } } if (configManager.PMAInfoObj.UseFTP) { try { List<string> ftpFiles = new List<string>(); ftpFiles.Add(_reportFileName); ftpTransport.FTPSend(configManager.FtpInfo, ftpFiles); } catch (Exception ex) { configManager.Logger.Error(ex); } } } } catch (Exception ex) { configManager.Logger.Error(ex); } finally { smtpTransport = null; ftpTransport = null; GC.Collect(); GC.WaitForPendingFinalizers(); _fileName = GenerateNewFileName(); SerializedPMAInfo(); configManager.Logger.Debug(EnumMethod.END); } } }
//---------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Reportings the task. /// </summary> public void ReportingTask() { configManager.Logger.Debug(EnumMethod.START); if (configManager.SystemAnalyzerInfo.SetPMA) { SMTPTransport smtpTransport = new SMTPTransport(); FTPTransport ftpTransport = new FTPTransport(); try { _reportFileName = string.Empty; if (File.Exists(_fileName)) { _reportFileName = CreateAllProcessCSVReport(_fileName); } if (DateTime.Now > mailingTime) { mailingTime = mailingTime.AddHours(configManager.PMAInfoObj.ReportsIntervalHours); configManager.PMAInfoObj.MailingTime = mailingTime; } if (File.Exists(_fileName)) { if (configManager.PMAInfoObj.UseSMTP) { try { string subject = "PMA System Alerts : PMA Report : " + configManager.SystemAnalyzerInfo.ClientInstanceName + " : " + Environment.MachineName + " : " + " at " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); List <string> attachments = new List <string>(); attachments.Add(_reportFileName); smtpTransport.SmtpSend(configManager.SmtpInfo, configManager.SystemAnalyzerInfo.ListPMAReportSubscription, null, subject, GenerateMailMessageBody(), attachments); } catch (InvalidOperationException ex) { configManager.Logger.Message(ex.Message); } catch (Exception ex) { configManager.Logger.Error(ex); } } if (configManager.PMAInfoObj.UseFTP) { try { List <string> ftpFiles = new List <string>(); ftpFiles.Add(_reportFileName); ftpTransport.FTPSend(configManager.FtpInfo, ftpFiles); } catch (Exception ex) { configManager.Logger.Error(ex); } } } } catch (Exception ex) { configManager.Logger.Error(ex); } finally { smtpTransport = null; ftpTransport = null; GC.Collect(); GC.WaitForPendingFinalizers(); _fileName = GenerateNewFileName(); SerializedPMAInfo(); configManager.Logger.Debug(EnumMethod.END); } } }
public void SendMail() { configManager.Logger.Debug(EnumMethod.START); string subject = string.Format(_subject, _alertType,configManager.SystemAnalyzerInfo.ClientInstanceName, _user); SMTPTransport smtp = new SMTPTransport(); try { smtp.SendAsynchronous = true; SaveLog(); smtp.SmtpSend(configManager.SmtpInfo, configManager.SystemAnalyzerInfo.ListAlertMailSubscription, null, subject, GenerateMessageBody(), null); } catch (Exception ex) { configManager.Logger.Error(ex); } configManager.Logger.Debug(EnumMethod.END); }
/// <summary> /// Sends the mail. /// </summary> /// <param name="subject">The subject.</param> /// <param name="mailBody">The mail body.</param> /// <param name="emails">The emails.</param> /// <param name="attachments">The attachments.</param> /// <returns></returns> public static bool SendMail(string subject, string mailBody, List<string> emails, List<string> attachments) { logger.Debug(EnumMethod.START); SMTPTransport smtpTransport = new SMTPTransport(); bool success = false; try { smtpTransport.SmtpSend(configManager.SmtpInfo, emails, null, subject, mailBody, attachments); success = true; } catch(Exception ex) { success = false; logger.Error(ex); } finally { logger.Debug(EnumMethod.END); } return success; }