示例#1
0
        /// <summary>
        /// Generic Method to Create Email Content
        /// </summary>
        /// <param name="payload">
        /// Payload of the request for the template service
        /// </param>
        /// <param name="path">
        /// Path of the template service
        /// </param>
        /// <param name="subjectLine">
        /// Subject Line of the content
        /// </param>
        /// <returns>
        /// Notification Content
        /// </returns>
        private async Task <NotificationContent> CreateEmailContentAsync(string payload, string path, string subjectLine)
        {
            string htmlBody = await RetrieveTemplateAsync(
                path,
                payload).ConfigureAwait(false);

            string textBody = await RetrieveTemplateAsync(
                path,
                payload,
                "text/plain").ConfigureAwait(false);

            NotificationContent content = new NotificationContent()
            {
                HtmlBody = htmlBody,
                TextBody = textBody,
                Subject  = subjectLine
            };

            return(content);
        }
示例#2
0
        /// <summary>
        /// Create Auth Sms Content
        /// </summary>
        /// <param name="data">
        /// Auth Sms Notification Data
        /// </param>
        /// <param name="templatePath">Template path</param>
        /// <returns>
        /// Notification content
        /// </returns>
        public async Task <NotificationContent> CreateAuthSmsContentAsync(AuthSmsNotificationData data, string templatePath = authSmsTemplatePathClo)
        {
            try
            {
                string textBody = await RetrieveTemplateAsync(
                    TemplateServiceBaseAddress + templatePath,
                    JsonConvert.SerializeObject(data)).ConfigureAwait(false);

                NotificationContent content = new NotificationContent()
                {
                    TextBody = textBody,
                };

                return(content);
            }
            catch (Exception exception)
            {
                Logger.Warning("Unable to create content for Auth Sms \r\n" +
                               "Data : \r\n" +
                               "{0}", data, exception);
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Sends an email notification in response to an event.
        /// </summary>
        /// <param name="toAddress">
        /// E-mail address to which to send the notification.
        /// </param>
        /// <param name="content">
        /// Content of the email payload
        /// </param>
        /// <param name="isEarn">Is Earn</param>
        internal void SendEmailNotification(string toAddress, NotificationContent content, bool isEarn = false)
        {
            string fromAddress = isEarn ? FromAddressEarn : FromAddressClo;
            string fromDisplay = isEarn ? FromFieldTextEarn : FromFieldTextClo;

            // Build the send e-mail request.
            EmailContent emailContent = new EmailContent
            {
                From        = fromAddress,
                FromDisplay = fromDisplay,
                Subject     = content.Subject,
                HtmlBody    = content.HtmlBody,
                TextBody    = content.TextBody
            };

            SendEmailRequest sendEmailRequest = new SendEmailRequest
            {
                Content = emailContent,
                IsTest  = false,
                ToList  = new List <string> {
                    toAddress
                }
            };

            // Send the e-mail.
            try
            {
                // Use a generous timeout to ensure best chance of success. Because this can be a time consuming call, consumers
                //  should run notifications on a separate thread.
                UserServicesClient.SendEmail(Context.Log.ActivityId, sendEmailRequest, new TimeSpan(0, 0, 0, 5, 0));
            }
            catch (HttpRequestException ex)
            {
                Context.Log.Warning("Unable to send notification. {0}", ex.Message);
            }
        }