private static IEnumerable <CRSMEmail> Send(int?accountId, Message message, string format, IEnumerable <NotificationRecipient> additionalRecipients, Int32?TemplateID) { var graph = new PXGraph(); var activitySource = message.Relationship.ActivitySource; Guid?refNoteID = GetEntityNoteID(graph, activitySource); var bacc = message.Relationship.ParentSource as BAccount; int?bAccountID = bacc != null ? bacc.BAccountID : null; NotificationGenerator sender = null; if (TemplateID != null) { sender = TemplateNotificationGenerator.Create(activitySource, (int)TemplateID); } else if (!string.IsNullOrEmpty(message.TemplateID)) { sender = TemplateNotificationGenerator.Create(activitySource, message.TemplateID); } if (sender == null) { sender = new NotificationGenerator(graph); } sender.Body = string.IsNullOrEmpty(sender.Body) ? message.Content.Body : sender.Body; sender.Subject = string.IsNullOrEmpty(sender.Subject) ? message.Content.Subject : sender.Subject; sender.MailAccountId = accountId; sender.Reply = accountId. With(_ => (EMailAccount)PXSelect <EMailAccount, Where <EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > > . Select(graph, _.Value)). With(_ => _.Address); sender.To = message.Addressee.To; sender.Cc = message.Addressee.Cc; sender.Bcc = message.Addressee.Bcc; sender.RefNoteID = refNoteID; sender.BAccountID = bAccountID; sender.BodyFormat = PXNotificationFormatAttribute.ValidBodyFormat(format); List <NotificationRecipient> watchers = new List <NotificationRecipient>(); if (sender.Watchers != null) { watchers.AddRange(sender.Watchers); } if (additionalRecipients != null) { watchers.AddRange(additionalRecipients); } sender.Watchers = watchers; foreach (ReportStream attachment in message.Attachments) { sender.AddAttachment(attachment.Name, attachment.GetBytes()); } return(sender.Send()); }
protected IEnumerable <EPActivity> CreateMessages() { var result = new List <EPActivity>(); EPActivity main = CreateMessage(); if (Watchers != null && Watchers.Any()) { bool isMainAddedd = false; foreach (NotificationRecipient n in Watchers) { EPActivity m; var format = PXNotificationFormatAttribute.ValidBodyFormat(n.Format); if (format == main.Format) { m = main; } else { BodyFormat = format; m = CreateMessage(); } if (n.Hidden == true) { m.MailBcc += (!string.IsNullOrEmpty(m.MailBcc) ? ";" : string.Empty) + n.Email; } else { if (string.IsNullOrEmpty(m.MailTo)) { m.MailTo = n.Email; } else { m.MailCc += (!string.IsNullOrEmpty(m.MailCc) ? ";" : string.Empty) + n.Email; } } if (m.TaskID != main.TaskID || !isMainAddedd) { result.Add(m); } isMainAddedd |= m.TaskID == main.TaskID; } } else { result.Add(main); } if (result.Count == 0) { throw new PXException(Messages.MailToUndefined); } for (int i = result.Count - 1; i >= 0; i--) { var item = result[i]; var mail = item; if (string.IsNullOrEmpty(mail.MailTo)) { if (!string.IsNullOrEmpty(mail.MailCc)) { string list = mail.MailCc; mail.MailTo = GetFirstMail(ref list); if (mail.MailTo != null) { mail.MailCc = list; } } if (!string.IsNullOrEmpty(mail.MailBcc)) { string list = mail.MailBcc; mail.MailTo = GetFirstMail(ref list); if (mail.MailTo != null) { mail.MailBcc = list; } } if (string.IsNullOrEmpty(mail.MailTo)) { Graph.Caches[typeof(EPActivity)].Delete(item); result.RemoveAt(i); PXTrace.WriteInformation(Messages.MailToUndefined); } } } return(result); }