Пример #1
0
        /// <summary>
        /// Send unsubscribe mail to user.
        /// </summary>
        /// <param name="userDetail">User details.</param>
        private static void SendUnsubscribeMailToUser(Tuple <string, string, string, DateTime> userDetail)
        {
            var subject  = string.Format("Hi {0}! Would you like to unsubscribe?‏", userDetail.Item1);
            var mailBody = UnsubscribeTemplateString.Replace("[NAME]", userDetail.Item1).Replace("[CODESTRING]", userDetail.Item2);

            mailSystem.SendEmail(userDetail.Item3, MailerAddress, MailerName, subject, mailBody);
        }
Пример #2
0
        /// <summary>
        /// Send reminder mail.
        /// </summary>
        /// <param name="userDetail">The user details.</param>
        /// <returns>State of operation.</returns>
        private static bool SendReminderMail(Tuple <string, string, string, DateTime> userDetail)
        {
            try
            {
                var subject  = string.Format("[Reminder] Hi {0}! Please Activate Your Subscription!‏", userDetail.Item1);
                var mailBody =
                    TemplateString.Replace("[NAME]", userDetail.Item1)
                    .Replace("[CODESTRING]", userDetail.Item2)
                    .Replace(
                        "[DATEOFEXPIRY]",
                        (userDetail.Item4 + TimeSpan.FromDays(7)).ToLocalTime().ToString("f"));
                mailSystem.SendEmail(userDetail.Item3, MailerAddress, MailerName, subject, mailBody);
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine("Error at Time:{0} Exception:{1}", DateTime.UtcNow, exception);
                return(false);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        ///     Sends the new post mails to users.
        /// </summary>
        /// <param name="userDetails">The user details.</param>
        /// <param name="title">The title.</param>
        /// <param name="postedDate">The posted date.</param>
        /// <param name="formattedUri">The formatted URI.</param>
        /// <param name="bodySnippet">The body snippet.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool SendNewPostMailsToUsers(
            IEnumerable <Tuple <string, string, string> > userDetails,
            string title,
            DateTime?postedDate,
            string formattedUri,
            string bodySnippet)
        {
            try
            {
                var subject = string.Format("New blog posted on rahulrai.in: {0}", title);
                Parallel.ForEach(
                    userDetails,
                    userDetail =>
                {
                    Console.Out.WriteLine("Sending mail to {0}", userDetail.Item2);
                    var mailBody =
                        TemplateString.Replace("[NAME]", userDetail.Item1)
                        .Replace("[BLOGTITLE]", title)
                        .Replace("[BODYSNIP]", bodySnippet)
                        .Replace("[POSTLINK]", formattedUri)
                        .Replace("[CODESTRING]", userDetail.Item3)
                        .Replace(
                            "[POSTDATE]",
                            (postedDate ?? DateTime.MinValue).ToLocalTime().ToString("f"));
                    mailSystem.SendEmail(userDetail.Item2, MailerAddress, MailerName, subject, mailBody);
                    Console.Out.WriteLine("Mail sent to {0}", userDetail.Item2);
                });
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine("Error at Time:{0} Message:{1}", DateTime.UtcNow, exception);
                return(false);
            }

            return(true);
        }