Example #1
0
        /// <summary>
        /// The is send time window valid.
        /// </summary>
        /// <param name="lastEmailEntity">
        /// The last email entity.
        /// </param>
        /// <param name="remainderEmailCargo">
        /// The job.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool IsSendTimeWindowValid(UserEmailEntity lastEmailEntity, PromotionalEmailCargo remainderEmailCargo)
        {
            bool isSendTimeWindowValid = true;

            if (lastEmailEntity != null && lastEmailEntity.EmailDate > (DateTime.UtcNow - this._windowsBetweenRemainderEmails))
            {
                Log.Error(
                    "Can't send remainder email due to time windows constraint. Job Details=[{0}]; Last Email Date={1}; Window Between Emails={2}",
                    remainderEmailCargo.ToString(),
                    lastEmailEntity.EmailDate,
                    this._windowsBetweenRemainderEmails);

                isSendTimeWindowValid = false;
            }

            return(isSendTimeWindowValid);
        }
Example #2
0
        /// <summary>
        /// Returns the email content for add card remainder email
        /// </summary>
        /// <param name="remainderEmailCargo">Remainder email cargo</param>
        /// <returns>EmailData for add card remainder email</returns>
        private EmailData GetContentForCompleteSignup(PromotionalEmailCargo remainderEmailCargo)
        {
            EmailData emailData;
            EmailRenderingClient <object> emailRenderingClient = new EmailRenderingClient <object>
            {
                EmailRenderingServiceUrl = remainderEmailCargo.EmailRenderingServiceAddress
            };

            emailData = new EmailData
            {
                Subject  = remainderEmailCargo.Subject,
                HtmlBody = emailRenderingClient.RenderHtml(),
                TextBody = string.Empty
            };

            return(emailData);
        }
Example #3
0
        /// <summary>
        /// Handles the Remainder email job
        /// </summary>
        /// <param name="emailCargo">RemainderEmail cargo</param>
        public void Handle(EmailCargo emailCargo)
        {
            PromotionalEmailCargo remainderEmailCargo = emailCargo as PromotionalEmailCargo;

            if (remainderEmailCargo != null)
            {
                var emailHistoryEntities = this._userHistoryStorage.GetUserEmailEntities(remainderEmailCargo.UserId, _mailHistoryLookback).ToList();
                if (this.IsSendTimeWindowValid(emailHistoryEntities.FirstOrDefault(elem => string.Compare(elem.EmailType, EmailType.CompleteSignup.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0), remainderEmailCargo))
                {
                    EmailData    emailData    = _emailContentCreator.GetContent(remainderEmailCargo);
                    bool         isTest       = (remainderEmailCargo.Hints != null) && remainderEmailCargo.Hints.IsTest;
                    EmailContent emailContent = new EmailContent
                    {
                        From        = isTest ? this._emailFromAddressTestAccount : this._emailFromAddress,
                        FromDisplay = this._emailFromDisplay,
                        Subject     = emailData.Subject,
                        HtmlBody    = emailData.HtmlBody,
                        TextBody    = emailData.TextBody,
                        Category    = remainderEmailCargo.Campaign
                    };
                    SendEmailRequest request = new SendEmailRequest
                    {
                        Content = emailContent,
                        ToList  = new List <string> {
                            remainderEmailCargo.EmailAddress
                        },
                        IsTest = isTest
                    };

                    // Send the email
                    this._userServicesClient.SendEmail(remainderEmailCargo.Id, request, null);

                    PromotionalEmailType remainderType;
                    if (Enum.TryParse(remainderEmailCargo.PromotionalEmailType, true, out remainderType))
                    {
                        // Saving the email data in the history table
                        UserEmailEntity emailToSend = new UserEmailEntity(remainderEmailCargo.UserId, string.Empty, DateTime.UtcNow, EmailType.CompleteSignup);
                        this._userHistoryStorage.SaveUserEmailEntity(emailToSend);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Returns the email content for remainder email
        /// </summary>
        /// <param name="emailCargo">Remainder Email cargo</param>
        /// <returns>EmailData for the remainder email</returns>
        public EmailData GetContent(object emailCargo)
        {
            PromotionalEmailCargo remainderEmailCargo = emailCargo as PromotionalEmailCargo;
            EmailData             emailData           = null;

            if (remainderEmailCargo != null)
            {
                PromotionalEmailType remainderType;
                if (Enum.TryParse(remainderEmailCargo.PromotionalEmailType, true, out remainderType))
                {
                    switch (remainderType)
                    {
                    case PromotionalEmailType.CompleteSignup:
                        emailData = GetContentForCompleteSignup(remainderEmailCargo);
                        break;
                    }
                }
            }
            return(emailData);
        }