/// <summary> /// This method sends mail according to the parameter /// </summary> /// <param name="operation">parameters for MailSend</param> /// <returns>true if processed successfully, false otherwise</returns> private bool MailSend(MailSimOperationsMailSend operation) { int iterations = GetIterationCount(operation.Count); if (iterations < 1) { Log.Out(Log.Severity.Error, operation.OperationName, "Count is less than the minimum allowed value", iterations); return(false); } for (int count = 1; count <= iterations; count++) { try { // generates a new email IMailItem mail = olMailStore.NewMailItem(); mail.Subject = DateTime.Now.ToString() + " - "; mail.Subject += (string.IsNullOrEmpty(operation.Subject)) ? DefaultSubject : operation.Subject; Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mail.Subject); mail.Body = BuildBody(operation.Body); Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mail.Body); if (!AddRecipients(mail, operation)) { return(false); } AddAttachments(mail, operation); mail.Send(); } catch (Exception ex) { Log.Out(Log.Severity.Error, operation.OperationName, "Exception encountered\n" + ex); return(false); } SleepOrStop(operation.OperationName, operation.Sleep); } return(true); }
/// <summary> /// This method sends mail according to the parameter /// </summary> /// <param name="operation">parameters for MailSend</param> /// <returns>true if processed successfully, false otherwise</returns> private bool MailSend(MailSimOperationsMailSend operation) { int iterations = GetIterationCount(operation.Count); if (iterations < 1) { Log.Out(Log.Severity.Error, operation.OperationName, "Count is less than the minimum allowed value", iterations); return false; } for (int count = 1; count <= iterations; count++) { // generates a new email IMailItem mail = olMailStore.NewMailItem(); mail.Subject = DateTime.Now.ToString() + " - "; mail.Subject += (string.IsNullOrEmpty(operation.Subject)) ? DefaultSubject : operation.Subject; Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mail.Subject); mail.Body = BuildBody(operation.Body); Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mail.Body); if (!AddRecipients(mail, operation)) { return false; } AddAttachments(mail, operation); mail.Send(); SleepOrStop(operation.OperationName, operation.Sleep); } return true; }
/// <summary> /// This method sends mail according to the parameter /// </summary> /// <param name="operation">parameters for MailSend</param> /// <returns>true if processed successfully, false otherwise</returns> private bool MailSend(MailSimOperationsMailSend operation) { int iterations = GetIterationCount(operation.Count); if (iterations < 1) { Log.Out(Log.Severity.Error, operation.OperationName, "Count is less than the minimum allowed value", iterations); return false; } for (int count = 1; count <= iterations; count++) { List<string> recipients = GetRecipients(operation.OperationName, operation.RecipientType, operation.Recipients); if (recipients == null) { Log.Out(Log.Severity.Error, operation.OperationName, "Recipient is not specified, skipping the operation"); return false; } List<string> attachments = GetAttachments(operation.OperationName, operation.Attachments); try { // generates a new email IMailItem mail = olMailStore.NewMailItem(); mail.Subject = mail.Body = System.DateTime.Now.ToString() + " - "; mail.Subject += (string.IsNullOrEmpty(operation.Subject)) ? DefaultSubject : operation.Subject; Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mail.Subject); mail.Body += (string.IsNullOrEmpty(operation.Body)) ? DefaultBody : operation.Body; Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mail.Body); // Adds all recipients foreach (string recpt in recipients) { Log.Out(Log.Severity.Info, operation.OperationName, "Recipient: {0}", recpt); mail.AddRecipient(recpt); } // processes the attachment foreach (string attmt in attachments) { Log.Out(Log.Severity.Info, operation.OperationName, "Attachment: {0}", attmt); mail.AddAttachment(attmt); } mail.Send(); } catch (Exception ex) { Log.Out(Log.Severity.Error, operation.OperationName, "Exception encountered\n" + ex); return false; } SleepOrStop(operation.OperationName, operation.Sleep); } return true; }