示例#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());
        }
示例#2
0
        protected override bool Process(Package package)
        {
            var account = package.Account;

            if (account.IncomingProcessing != true ||
                account.ConfirmReceipt != true ||
                account.ConfirmReceiptNotificationID == null)
            {
                return(false);
            }

            var templateId = (int)account.ConfirmReceiptNotificationID;
            var message    = package.Message;
            var sender     = TemplateNotificationGenerator.Create(message, templateId);

            sender.LinkToEntity  = false;
            sender.MailAccountId = account.EmailAccountID;
            sender.Send();

            return(true);
        }