private static void SendMultipleTaskEmailThroughCCM(CCMService.EmailRecipient emailRecipient, List <UserTaskEmail> lstTasks, int siteId, int userId, int templateId, int actionTypeId) { string FromEmailAddress = ConfigurationManager.AppSettings["AMPFromEmailAddress"]; List <CCMService.TaskDetail> lstTaskDetails = new List <CCMService.TaskDetail>(); string taskIds = string.Join(",", lstTasks.Select(a => a.TaskID)); foreach (var task in lstTasks) { lstTaskDetails.Add(GetCCMTaskDetail(task)); } if (emailRecipient.FullName == "JCRFirstName JCRLastName") { emailRecipient.FullName = "Guest User"; //This will be replaced in Email Salutations } CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.TaskMailDetail taskMailDetail = new CCMService.TaskMailDetail(); taskMailDetail.FromEmail = FromEmailAddress; taskMailDetail.SiteID = siteId; taskMailDetail.TemplateID = templateId; taskMailDetail.UserID = userId; taskMailDetail.ActionTypeID = actionTypeId; taskMailDetail.ApplicationCode = ApplicationCode.TracerswithAMP.ToString(); taskMailDetail.EmailRecipients = new List <CCMService.EmailRecipient>(); taskMailDetail.EmailRecipients.Add(emailRecipient); oEmail.SendTasksEmail(taskMailDetail, lstTaskDetails); }
private static void SendTaskEmailForCCUsersThroughCCM(UserTaskEmail task, string taskIDs, CCMService.EmailRecipient emailRecipients, List <AssignedToUserTaskEmail> lstTaskAssignees, int siteId, int userId, int templateId, int actionTypeId) { string FromEmailAddress = ""; switch ((TaskType)task.TaskTypeID) { case TaskType.Generic: case TaskType.AMPEP: case TaskType.CMSStandard: FromEmailAddress = ConfigurationManager.AppSettings["AMPFromEmailAddress"]; break; case TaskType.Tracer: case TaskType.TracerObservation: case TaskType.TracerObservationQuestion: FromEmailAddress = ConfigurationManager.AppSettings["TracerFromEmailAddress"]; break; } CCMService.TaskDetail taskDetail = GetCCMTaskDetail(task); var assignees = (from l in lstTaskAssignees select new { Assignee = l.AssignedToFullName == "JCRFirstName JCRLastName" ? l.AssignedToEmail : l.AssignedToFormattedName // this will be replaced in Email Task Detail }).Select(a => a.Assignee).ToList <string>(); taskDetail.AssignedTo = string.Join("; ", assignees); taskDetail.TaskIDs = taskIDs; if (emailRecipients.FullName == "JCRFirstName JCRLastName") { emailRecipients.FullName = "Guest User"; //This will be replaced in Email Salutations } CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.TaskMailDetail taskMailDetail = new CCMService.TaskMailDetail(); taskMailDetail.FromEmail = FromEmailAddress; taskMailDetail.SiteID = siteId; taskMailDetail.TemplateID = templateId; taskMailDetail.UserID = userId; taskMailDetail.ActionTypeID = actionTypeId; taskMailDetail.ApplicationCode = ApplicationCode.TracerswithAMP.ToString(); taskMailDetail.EmailRecipients = new List <CCMService.EmailRecipient>(); taskMailDetail.EmailRecipients.Add(emailRecipients); oEmail.SendTaskEmailAsync(taskMailDetail, taskDetail); }
private static void SendTaskEmailThroughCCM(UserTaskEmail task, List <CCMService.EmailRecipient> lstEmailRecipients, int siteId, int userId, int templateId, int actionTypeId) { string FromEmailAddress = ""; switch ((TaskType)task.TaskTypeID) { case TaskType.Generic: case TaskType.AMPEP: case TaskType.CMSStandard: FromEmailAddress = ConfigurationManager.AppSettings["AMPFromEmailAddress"]; break; case TaskType.Tracer: case TaskType.TracerObservation: case TaskType.TracerObservationQuestion: FromEmailAddress = ConfigurationManager.AppSettings["TracerFromEmailAddress"]; break; } CCMService.TaskDetail taskDetail = GetCCMTaskDetail(task); lstEmailRecipients.ForEach(a => a.FullName = a.FullName == "JCRFirstName JCRLastName" ? "Guest User" : a.FullName); //This will be replaced in Email Salutations CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.TaskMailDetail taskMailDetail = new CCMService.TaskMailDetail(); taskMailDetail.FromEmail = FromEmailAddress; taskMailDetail.SiteID = siteId; taskMailDetail.TemplateID = templateId; taskMailDetail.UserID = userId; taskMailDetail.ActionTypeID = actionTypeId; taskMailDetail.ApplicationCode = ApplicationCode.TracerswithAMP.ToString(); taskMailDetail.EmailRecipients = lstEmailRecipients; oEmail.SendTaskEmailAsync(taskMailDetail, taskDetail); }
public static void SendSMTPEmail(string to, string cc, string bcc, string replyTo, string subject, string body, string attachment, bool isError, string sMTPServer, string emailUserName, string emailPassword, string emailErrorTo, string emailTestsTo, string emailFrom, int userId, int siteId) { MailMessage message = new MailMessage(); if (isError) { message.To.Add(emailErrorTo); } else { if (emailTestsTo.Length > 0) { string[] addresses = emailTestsTo.TrimEnd(';').Split(';'); foreach (string semail in addresses) { message.To.Add(semail); } } else { string[] toEmails = to.TrimEnd(';').Split(';'); foreach (string email in toEmails) { message.To.Add(email); } if (cc.Length > 0) { string[] ccEmails = cc.TrimEnd(';').Split(';'); foreach (string email in ccEmails) { message.CC.Add(email); } } if (bcc.Length > 0) { string[] bccEmails = bcc.TrimEnd(';').Split(';'); foreach (string email in bccEmails) { message.Bcc.Add(email); } } } } if (replyTo.Length > 0) { message.ReplyToList.Add(new MailAddress(replyTo)); } message.From = new MailAddress(emailFrom); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; if (attachment.Length > 0) { var item = new Attachment(attachment); message.Attachments.Add(item); } if (sMTPServer.Length > 0) { try { SmtpClient client = new SmtpClient(sMTPServer); client.UseDefaultCredentials = false; //if (emailUserName.Length > 0) // client.Credentials = new NetworkCredential(emailUserName, emailPassword); //Send mail using CCM implementation string applicationCode = Enums.ApplicationCode.Tracers.ToString(); int actionTypeId = (int)Enums.ActionTypeEnum.TracersEmailed; string fnReturnValue = string.Empty; // Invoke the CCM Service to send the email CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.MailDetails mailDetails = new CCMService.MailDetails(); mailDetails.EmailTo = message.To.ToString(); mailDetails.FromEmail = emailFrom; mailDetails.EmailCC = message.CC.ToString(); mailDetails.EmailBCC = message.Bcc.ToString(); mailDetails.MailSubject = message.Subject; mailDetails.MailContent = message.Body; mailDetails.SiteID = siteId; oEmail.SendGeneralEmail(mailDetails, ref fnReturnValue, applicationCode, actionTypeId, userId); } catch (Exception) { if (!isError) { throw; } } } }
public static void SendEmail(Email email, int actionTypeId, int siteId, int userId, string siteName, string fullName) { SmtpClient smt = new SmtpClient(); MailMessage siteEmail = new MailMessage(); siteEmail.IsBodyHtml = true; siteEmail.Body = email.Body; siteEmail.From = new MailAddress(ConfigurationManager.AppSettings["TracerFromEmailAddress"]); siteEmail.To.Add(emaillist(email.To).ToString()); if (email.Cc != null && email.Cc.Length > 0) { siteEmail.CC.Add(emaillist(email.Cc).ToString()); } if (email.Bcc != null && email.Bcc.Length > 0) { siteEmail.Bcc.Add(emaillist(email.Bcc).ToString()); } //siteEmail.Bcc.Add(emaillist(ConfigurationManager.AppSettings["BCCEmailAddress"]).ToString()); if (email.Subject != null && email.Subject.Length > 0) { siteEmail.Subject = email.Subject; } else { siteEmail.Subject = siteName + "-Tracers: " + email.Title + " Sent to you by " + fullName; } string smtpServer = null; //****************Send It!!! try { smtpServer = ConfigurationManager.AppSettings["TracerSMTPserver"]; //if (email.AttachmentLocation != null && email.AttachmentLocation.Capacity > 0) //{ // foreach (string filelocation in email.AttachmentLocation) // { // if (filelocation!=null && filelocation != "") // { // var item = new Attachment(filelocation); // siteEmail.Attachments.Add(item); // } // } //} string applicationCode = Enums.ApplicationCode.Tracers.ToString(); string fnReturnValue = string.Empty; // Invoke the CCM Service to send the email CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.MailDetails mailDetails = new CCMService.MailDetails(); mailDetails.EmailTo = siteEmail.To.ToString(); mailDetails.FromEmail = siteEmail.From.ToString(); mailDetails.EmailCC = email.Cc; mailDetails.EmailBCC = email.Bcc; mailDetails.MailSubject = siteEmail.Subject; mailDetails.MailContent = siteEmail.Body; mailDetails.SiteID = siteId; mailDetails.Guid = email.Guid; oEmail.SendGeneralEmail(mailDetails, ref fnReturnValue, applicationCode, actionTypeId, userId); } catch (Exception ex) { throw ex; } }
public static void SendEmail(Email email, int actionTypeId, string EmailFrom = "") { SmtpClient smt = new SmtpClient(); MailMessage siteEmail = new MailMessage(); siteEmail.IsBodyHtml = true; siteEmail.Body = email.Body; // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; if (EmailFrom.Length > 0) { siteEmail.From = new MailAddress(ConfigurationManager.AppSettings[EmailFrom]); } else { if (AppSession.LinkType == 10) { siteEmail.From = new MailAddress(ConfigurationManager.AppSettings["FromEREmailAddress"]); } else if (AppSession.LinkType == 11) { siteEmail.From = new MailAddress(ConfigurationManager.AppSettings["FromAMPEmailAddress"]); } else { siteEmail.From = new MailAddress(ConfigurationManager.AppSettings["FromEmailAddress"]); } } siteEmail.To.Add(emaillist(email.To).ToString()); if (email.Cc != null && email.Cc.Length > 0) { if (email.Cc != "[email protected];[email protected]") { siteEmail.CC.Add(emaillist(email.Cc).ToString()); } } if (email.Bcc != null && email.Bcc.Length > 0) { if (email.Bcc != "[email protected];[email protected]") { siteEmail.Bcc.Add(emaillist(email.Bcc).ToString()); } } //siteEmail.Bcc.Add(emaillist(ConfigurationManager.AppSettings["BCCEmailAddress"]).ToString()); //Subject Line: //[HCOID/SiteID] - [Application Name]: Report Name – “Sent to you by” [first name]&[Last Name] //HCO ID: 337845: Tracers: Comprehensive Scoring Report – Sent to you by Chastity Dailey if (email.Subject != null && email.Subject.Length > 0) { siteEmail.Subject = email.Subject; // +"-" + AppSession.SelectedSiteName + "-Tracers: " + email.Title + " Sent to you by " + AppSession.FullName; } else { if (AppSession.LinkType == 11) { siteEmail.Subject = "AMP: " + email.Title + " Sent to you by " + AppSession.FullName; } else { siteEmail.Subject = AppSession.SelectedSiteName + "-Tracers: " + email.Title + " Sent to you by " + AppSession.FullName; } } string smtpServer = null; //****************Send It!!! try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; smtpServer = ConfigurationManager.AppSettings["SMTPserver"]; //if (email.AttachmentLocation != null && email.AttachmentLocation.Capacity > 0) //{ // foreach (string filelocation in email.AttachmentLocation) // { // if (filelocation != "") // { // var item = new Attachment(filelocation); // siteEmail.Attachments.Add(item); // } // } //} string applicationCode = ApplicationCode.Reports.ToString(); int userId = (int)AppSession.UserID; string fnReturnValue = string.Empty; int siteId = (int)AppSession.SelectedSiteId; List <string> guidList = new List <string>(); // Invoke the CCM Service to send the email CCMService.ProcessEmailClient oEmail = new CCMService.ProcessEmailClient(); CCMService.MailDetails mailDetails = new CCMService.MailDetails(); mailDetails.EmailTo = siteEmail.To.ToString(); mailDetails.FromEmail = siteEmail.From.ToString(); mailDetails.EmailCC = email.Cc; mailDetails.EmailBCC = email.Bcc; mailDetails.MailSubject = siteEmail.Subject; mailDetails.MailContent = siteEmail.Body; mailDetails.SiteID = siteId; if (email.GuidList != null && email.GuidList.Length > 0) { foreach (string guid in email.GuidList) { if (guid != null) { guidList.Add(guid); } } } mailDetails.GuidList = guidList.ToArray(); int result = oEmail.SendGeneralEmail(mailDetails, ref fnReturnValue, applicationCode, actionTypeId, userId); if (result != 1) { throw new Exception(fnReturnValue); } } catch (Exception ex) { throw ex; } }