Example #1
0
        public async void SendMailFromMandril(DateTime SecheduleDate, bool IsInstant)
        {
            MassMailHelper conMassMail = new MassMailHelper(_httpContextAccessor, _env, _memoryCache);
            SendsEmail     sendsEmail  = await conMassMail.GetMailAndUserToSendMail(SecheduleDate.ToString());

            MailSendInfo        mail         = sendsEmail.Mail;
            List <MailMergeVar> lstMergeVars = new List <MailMergeVar>();
            EmailMessage        message      = new EmailMessage();

            if (mail != null)
            {
                message.from_email = mail.MailFrom;
                message.from_name  = mail.MailFrom;
                message.subject    = mail.Subject;
                List <EmailAddress> toEmails = new List <EmailAddress>();
                message.html = this.ConvertAllMergeTagsToMandrillsTags(mail.MessageBody);
                foreach (UserInfo subcriber in sendsEmail.Subscribers)
                {
                    if (!string.IsNullOrEmpty(subcriber.EmailAddress))
                    {
                        toEmails.Add(new EmailAddress(subcriber.EmailAddress, subcriber.FullName, "to"));
                        lstMergeVars.Add(new MailMergeVar {
                            rcpt = subcriber.EmailAddress, vars = this.GetSubscriberMergeVars(subcriber.TokenValues, mail.TokenKeys)
                        });
                    }
                }
                message.to         = toEmails;
                message.merge_vars = lstMergeVars;
                FinalEmail finalEmail = new FinalEmail();
                finalEmail.async   = true;
                finalEmail.message = message;

                if (!IsInstant)
                {
                    finalEmail.send_at = SecheduleDate.ToString(MandrilConfiguration.DATE_TIME_FORMAT_STRING);
                }
                string ApiKey = await MailSettingController.GetSettingByKey(MailSettingKey.MandrilAPIKey);

                MandrilHelper      mandrilMailHelper = new MandrilHelper(ApiKey);
                List <EmailResult> emailResults      = await mandrilMailHelper.SendMessage(finalEmail);

                MassMailProvider massMailProvider = new MassMailProvider();
                if (emailResults != null)
                {
                    await massMailProvider.UpdateStausOfFailMail(mail.MassMailID, string.Empty);

                    foreach (EmailResult objResult in emailResults)
                    {
                        await massMailProvider.AddMailSubscriberStatus(mail.MassMailID, objResult.Email, (int)objResult.Status, 1, objResult.RejectReason);
                    }
                }
            }
        }
Example #2
0
        private void CallMailGateway(DateTime ScheduleDate, bool IsInstant, string HostURL)
        {
            string GateWay = MailSettingController.GetSettingByKey(MailSettingKey.EMailGateWay).Result.ToLower();

            if (GateWay == "contentder")
            {
                Task.Run(() => SendMailFromContentder(ScheduleDate, HostURL));
            }
            else if (GateWay == "mandrill")
            {
                MandrillMailController conMandrill = new MandrillMailController(_httpContextAccessor, _env, _memoryCache);
                Task.Run(() => conMandrill.SendMailFromMandril(ScheduleDate, IsInstant));
            }
        }
Example #3
0
        public async static Task <string> GetSettingByKey(string SettingsKey)
        {
            MailSettingController       conStng    = new MailSettingController();
            IList <MassMailSettingInfo> lstSetting = await conStng.GetAllSettings();

            foreach (MassMailSettingInfo objInfo in lstSetting)
            {
                if (objInfo.SettingKey == SettingsKey)
                {
                    return(objInfo.SettingValue);
                }
            }
            return(null);
        }