コード例 #1
0
        SentEmailMessage GenerateGroupEmailsToRecipientsList()
        {
            var recipientList         = GetArgumentValue <IEnumerable <IEntity> >(ActivityInputs, "core:sendEmailRecipientList");
            var recipientListTOField  = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientField");
            var recipientListCCField  = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientCCField");
            var recipientListBCCField = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientBCCField");

            if ((recipientListTOField == null) && (recipientListCCField == null) && (recipientListBCCField == null))
            {
                throw new Exception("A TO, CC or BCC recipient field has not been specified");
            }

            var mail = new SentEmailMessage()
            {
                EmIsHtml            = true,
                SentFromEmailServer = TenantEmailSetting,
                EmFrom     = FromAddress,
                EmFromName = FromName,
                EmTo       = (recipientListTOField != null) ? GetEmailAddressesFromRecipientsList(recipientList, recipientListTOField) : null,
                EmCC       = (recipientListCCField != null) ? GetEmailAddressesFromRecipientsList(recipientList, recipientListCCField) : null,
                EmBCC      = (recipientListBCCField != null) ? GetEmailAddressesFromRecipientsList(recipientList, recipientListBCCField) : null,
                EmSubject  = GetArgumentValue <string>(ActivityInputs, "core:sendEmailSubjectArgument"),
                EmBody     = GetArgumentValue <string>(ActivityInputs, "core:sendEmailBodyArgument")
            };

            var attachments = GetArgumentEntityList(ActivityInputs, "core:sendEmailAttachments");

            mail.EmAttachments.AddRange(Entity.Get <FileType>(attachments.Select(a => a.Id)));
            return(mail);
        }
コード例 #2
0
        /// <summary>
        ///     Converts the current SentEmailMessage to a MailMessage instance.
        /// </summary>
        /// <returns>
        ///     A new MailMessage instance that corresponds to this SentEmailMessage instance.
        /// </returns>
        public static MailMessage ToMailMessage(this SentEmailMessage sentEmailMessage)
        {
            if (sentEmailMessage == null)
            {
                throw new ArgumentNullException(nameof(sentEmailMessage));
            }

            MailMessage message = sentEmailMessage.As <EmailMessage>( ).ToMailMessage( );

            message.Headers[EmailHelper.SoftwarePlatformSequenceIdHeader] = sentEmailMessage.SemSequenceNumber;

            return(message);
        }
コード例 #3
0
        /// <summary>
        ///     Sends the email.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">
        ///     emailEntity
        ///     or
        ///     iCal
        ///     or
        ///     inbox
        /// </exception>
        private static void SendEmail(SentEmailMessage emailEntity, iCalendar iCal, TenantEmailSetting emailServerSettings)
        {
            if (emailEntity == null)
            {
                throw new ArgumentNullException("emailEntity");
            }

            if (iCal == null)
            {
                throw new ArgumentNullException("iCal");
            }

            if (emailServerSettings == null)
            {
                throw new ArgumentNullException("emailServerSettings");
            }


            /////
            // Send the email.
            /////
            iCalEmailHelper.SendICalEmail(iCal, emailEntity.ToMailMessage( ), emailServerSettings);
        }
コード例 #4
0
        /// <summary>
        /// This method is incomplete as it does not generate correctly use the Recipient list to generate the email subject and body components.
        /// </summary>
        /// <returns></returns>
        List <SentEmailMessage> GenerateIndividualEmailsToRecipientsList()
        {
            var recipientList         = GetArgumentValue <IEnumerable <IEntity> >(ActivityInputs, "core:sendEmailRecipientList");
            var recipientListTOField  = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientField");
            var recipientListCCField  = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientCCField");
            var recipientListBCCField = GetArgumentValue <IEntity>(ActivityInputs, "core:sendEmailRecipientBCCField");
            var attachments           = GetArgumentEntityList(ActivityInputs, "core:sendEmailAttachments");

            if ((recipientListTOField == null) && (recipientListCCField == null) && (recipientListBCCField == null))
            {
                throw new Exception("A TO, CC or BCC recipient field has not been specified");
            }

            //var recipients = Entity.Get<Resource>(recipientList.Select(e => e.Id), recipientField).ToArray();

            var emails = new List <SentEmailMessage>();

            foreach (var recipient in recipientList)
            {
                var mail = new SentEmailMessage()
                {
                    EmIsHtml            = true,
                    SentFromEmailServer = TenantEmailSetting,
                    EmFrom     = FromAddress,
                    EmFromName = FromName,
                    EmTo       = GetEmailAddressFromRecipientEntity(recipient, recipientListTOField),
                    EmCC       = GetEmailAddressFromRecipientEntity(recipient, recipientListCCField),
                    EmBCC      = GetEmailAddressFromRecipientEntity(recipient, recipientListBCCField),
                    EmSubject  = GetArgumentValue <string>(ActivityInputs, "core:sendEmailSubjectArgument"),
                    EmBody     = GetArgumentValue <string>(ActivityInputs, "core:sendEmailBodyArgument")
                };

                mail.EmAttachments.AddRange(Entity.Get <FileType>(attachments.Select(a => a.Id)));
                emails.Add(mail);
            }
            return(emails);
        }
コード例 #5
0
        SentEmailMessage GenerateEmailToRecipientsExpression()
        {
            var to  = GetArgumentValue <string>(ActivityInputs, "core:sendEmailRecipientArgument");
            var cc  = GetArgumentValue <string>(ActivityInputs, "core:sendEmailRecipientCCArgument");
            var bcc = GetArgumentValue <string>(ActivityInputs, "core:sendEmailRecipientBCCArgument");

            var mail = new SentEmailMessage()
            {
                EmIsHtml            = true,
                SentFromEmailServer = TenantEmailSetting,
                EmFrom     = FromAddress,
                EmFromName = FromName,
                EmTo       = GetValidEmailAddresses(to),
                EmCC       = GetValidEmailAddresses(cc),
                EmBCC      = GetValidEmailAddresses(bcc),
                EmSubject  = GetArgumentValue <string>(ActivityInputs, "core:sendEmailSubjectArgument"),
                EmBody     = GetArgumentValue <string>(ActivityInputs, "core:sendEmailBodyArgument")
            };

            var attachments = GetArgumentEntityList(ActivityInputs, "core:sendEmailAttachments");

            mail.EmAttachments.AddRange(Entity.Get <FileType>(attachments.Select(a => a.Id)));
            return(mail);
        }
コード例 #6
0
        public void Test()
        {
            string messageIdLocalPart;

            var sentMessage = new SentEmailMessage
            {
                EmTo      = "*****@*****.**",
                EmFrom    = "*****@*****.**",
                EmBody    = "body",
                EmIsHtml  = false,
                EmSubject = "subject"
            };

            sentMessage.Save( );

            messageIdLocalPart = sentMessage.SemSequenceNumber;

            var receivedMessage = new ReceivedEmailMessage
            {
                EmTo         = "*****@*****.**",
                EmFrom       = "*****@*****.**",
                EmSubject    = "Re: " + sentMessage.EmSubject,
                EmBody       = "body",
                EmIsHtml     = false,
                EmReferences = EmailHelper.GenerateMessageId(messageIdLocalPart, "localhost")
            };

            var matchAction = new MatchSentToReceivedEmailsAction( );

            Action postSaveAction;

            Assert.IsFalse(matchAction.BeforeSave(receivedMessage, out postSaveAction));
            Assert.IsNull(postSaveAction);
            Assert.IsNotNull(receivedMessage.OriginalMessage, "The original message has been found.");
            Assert.AreEqual(sentMessage.Id, receivedMessage.OriginalMessage.Id, "The original message has been set correctly.");
        }
コード例 #7
0
ファイル: EmailRouter.cs プロジェクト: hardin253874/Platform
        } = new EmailRouter();                                                // TODO: switch to DI

        public void Send(IEntity notifier, Notification notification, IEnumerable <IEntity> people, bool expectReply)
        {
            //
            // TODO: Refactor this and SendEmail
            // TODO: Deal with send failures
            // TODO: deal with replies
            //

            var sends = people.Select(p =>
            {
                var sendRecord = Entity.Create <SendRecord>();
                //receipt.NrReceiptToken = CryptoHelper.GetRandomPrintableString(16);               // TODO handle matching email responses
                sendRecord.SrToPerson         = p?.Cast <Person>();
                sendRecord.SendToNotification = notification;
                return(sendRecord);
            });

            var emailNotifier = notifier.Cast <EmailNotifier>();

            var inbox = notifier.GetRelationships("core:emailNotifierInbox").FirstOrDefault()?.As <Inbox>();

            if (inbox == null)
            {
                throw new ArgumentException("core:emailNotifierInbox");
            }

            var mail = new SentEmailMessage()
            {
                EmIsHtml = true, EmSentDate = DateTime.UtcNow,
            };

            var addresses = FetchAddresses(people, emailNotifier.EnEmailAddressExpression);

            sends = sends.Zip <SendRecord, string, SendRecord>(addresses, (send, address) =>
            {
                if (address == null)
                {
                    send.SrErrorMessage = MissingEmailAddressMessage;
                }
                return(send);
            });

            mail.EmTo = String.Join(",", addresses.Where(a => a != null));

            if (!string.IsNullOrEmpty(mail.EmTo))
            {
                mail.EmSubject = notifier.GetField <string>("core:enSubject");

                if (!string.IsNullOrEmpty(notification.NMessage))
                {
                    mail.EmBody = notification.NMessage;
                }

                var emailServerSettings = Entity.Get <TenantEmailSetting>("core:tenantEmailSettingsInstance");

                mail.EmFrom = inbox?.InboxEmailAddress;
                mail.SentFromEmailServer = emailServerSettings;
                mail.EmSentDate          = DateTime.UtcNow;
                mail.Save();

                var mailMessages = mail.Cast <SentEmailMessage>().ToMailMessage().ToEnumerable().ToList();

                var emailsender = new SmtpEmailSender(emailServerSettings);
                emailsender.SendMessages(mailMessages);
            }

            Entity.Save(sends);
        }
コード例 #8
0
        /// <summary>
        ///     Send reset password Email.
        /// </summary>
        /// <param name="displayName">The display name.</param>
        /// <returns></returns>
        private bool SendEmail(UserAccount account, string email, string tenant)
        {
            bool successSentEmail = false;

            try
            {
                account = account.AsWritable <UserAccount>();

                //only check current account is available or not
                if (account == null)
                {
                    return(successSentEmail);
                }

                string key = EDC.Security.CryptoHelper.GetMd5Hash(account.Id.ToString());
                if (account.PasswordReset != null)
                {
                    account.PasswordReset.AsWritable <PasswordResetRecord>();
                    account.PasswordReset.Delete();
                }


                account.PasswordReset = new PasswordResetRecord {
                    PasswordResetKey = key, PasswordResetExpiry = DateTime.UtcNow.AddDays(1.0)
                };
                account.Save();

                EventLog.Application.WriteInformation("set password reset key {0}", key);

                var mail = new SentEmailMessage()
                {
                    EmIsHtml = true, EmSentDate = DateTime.UtcNow,
                };

                string accountFullName = account.AccountHolder.FirstName + " " + account.AccountHolder.LastName;
                if (accountFullName.Trim().Length == 0)
                {
                    accountFullName = account.AccountHolder.Name;
                }

                //string toMail = email;
                const string subject   = "Reset Password - ReadiNow";
                string       link      = string.Format("{0}#/{1}/?key={2}&type=reset", Request.Headers.Referrer.ToString(), tenant, key);
                string       mailBoday = string.Format("Hi {0} <br> <br> We've received a request to reset your account {1} password for email address {2} <br> If you didn't make the request, please contact your administrator. <br> Otherwise, you can reset your password using this link: {3} <br><br>Best Regards, <br>ReadiNow", accountFullName, account.Name, email, link);

                var emailServer = ReadiNow.Model.Entity.Get <TenantEmailSetting>("tenantEmailSettingsInstance", TenantEmailSetting.AllFields);

                if (!string.IsNullOrEmpty(emailServer.SmtpServer) && !string.IsNullOrEmpty(emailServer.EmailNoReplyAddress))
                {
                    EventLog.Application.WriteInformation("Send user {0} reset password email to account '{1}' by email '{2}'", accountFullName, account.Name, email);

                    var sentMessage = new SentEmailMessage()
                    {
                        EmTo                = email,
                        EmFrom              = emailServer.EmailNoReplyAddress,
                        EmSubject           = subject,
                        EmBody              = mailBoday,
                        EmIsHtml            = true,
                        EmSentDate          = DateTime.UtcNow,
                        SentFromEmailServer = emailServer
                    };
                    sentMessage.Save();

                    var sender = new SmtpEmailSender(emailServer);
                    sender.SendMessages(sentMessage.ToMailMessage().ToEnumerable().ToList());
                }

                successSentEmail = true;
            }
            catch (Exception ex)
            {
                EventLog.Application.WriteError("Send Email: Unhandled internal exception: " + ex.ToString());
            }

            return(successSentEmail);
        }