Beispiel #1
0
        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());
        }
Beispiel #2
0
        public void Notify(int?accountId, string mailTo, string mailCc, string mailBcc, string subject, string body)
        {
            var sender = new NotificationGenerator
            {
                MailAccountId = accountId,
                To            = mailTo,
                Cc            = mailCc,
                Bcc           = mailBcc,
                Subject       = subject,
                Body          = body
            };

            sender.Send();
        }
        public void Notify(int?accountId, string mailTo, string mailCc, string mailBcc, string subject, string body, int?bAccountId,
                           int?contactId, Guid?refNoteId, Tuple <string, byte[]>[] attachments)
        {
            var sender = new NotificationGenerator
            {
                MailAccountId = accountId,
                To            = mailTo,
                Cc            = mailCc,
                Bcc           = mailBcc,
                Subject       = subject,
                Body          = body,
                BAccountID    = bAccountId,
                ContactID     = contactId,
                RefNoteID     = refNoteId
            };

            foreach (var attachment in attachments)
            {
                sender.AddAttachment(attachment.Item1, attachment.Item2);
            }
            sender.Send();
        }