Beispiel #1
0
        /// <summary>
        /// Create an EmailMessage based on a template.
        /// </summary>
        /// <param name="userId">The UserID to sent the email to.</param>
        /// <param name="from">The MailAddress to sent the email from, or NULL to use the site defaults.</param>
        /// <param name="emailTemplate">The <see cref="Constants.EmailTemplates"/> to send.</param>
        /// <param name="parameters">A list of <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailParameter"/>s, or null for none.</param>
        /// <param name="overrideRecipientText">n option text to add when the override recipient option is in use.  Leave blank tp get text from language sub-system</param>
        /// <returns>A <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailMessage"/>.</returns>
        public static EmailMessage EmailMessage(string userId, MailAddress from, Constants.EmailTemplates emailTemplate,
                                                List <EmailParameter> parameters = null, String overrideRecipientText = "")
        {
            var db   = new ProviderPortalEntities();
            var user = db.AspNetUsers.First(x => x.Id == userId);
            var to   = new MailAddress(user.Email, user.Name);

            return(EmailMessage(to, null, null, emailTemplate, parameters, overrideRecipientText));
        }
        /// <summary>
        /// Send an provider membership email to all organisation superusers.
        /// </summary>
        /// <param name="emailTemplate">The email template.</param>
        /// <param name="providerId">The provider identifier.</param>
        /// <param name="organisationId">The organisation identifier.</param>
        /// <param name="parameters">The parameters.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public static void SendOrganisationMembershipEmail(ProviderPortalEntities db,
                                                           Constants.EmailTemplates emailTemplate, int providerId, int organisationId, List <EmailParameter> parameters)
        {
            var organisationUsers = GetOrganisationUsers(db, organisationId, false, true).ToList();
            var provider          = db.Providers.FirstOrDefault(x => x.ProviderId == providerId);

            if (provider == null || !organisationUsers.Any())
            {
                return;
            }

            var to = new MailAddress(organisationUsers.First().Email, organisationUsers.First().Name);
            var cc = new MailAddressCollection();

            foreach (var user in organisationUsers.Skip(1))
            {
                cc.Add(new MailAddress(user.Email, user.Name));
            }

            if (parameters == null)
            {
                parameters = new List <EmailParameter>();
            }
            parameters.AddRange(new List <EmailParameter>
            {
                new EmailParameter("%PROVIDERNAME%", provider.ProviderName),
                new EmailParameter("%ORGANISATIONNAME%", organisationUsers.First().OrganisationName)
            });
            parameters.AddRange(parameters);

            //AppGlobal.EmailQueue.AddToSendQueue(
            //    TemplatedEmail.EmailMessage(
            //        to,
            //        cc,
            //        null,
            //        emailTemplate,
            //        parameters));

            var emailMessage = TemplatedEmail.EmailMessage(
                to,
                cc,
                null,
                emailTemplate,
                parameters);

            var response = SfaSendGridClient.SendGridEmailMessage(emailMessage, null, true);
        }
        /// <summary>
        /// Sends the new provision email.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="parameters">The parameters.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">template</exception>
        private static void SendNewProvisionEmail(Constants.EmailTemplates template, List <EmailParameter> parameters)
        {
            if (!(template == Constants.EmailTemplates.NewOrganisationNotification ||
                  template == Constants.EmailTemplates.NewProviderNotification))
            {
                throw new ArgumentOutOfRangeException("template");
            }

            if (parameters == null)
            {
                parameters = new List <EmailParameter>();
            }
            parameters.Add(new EmailParameter("%NAME%", Constants.ConfigSettings.SupportTeamEmailName));

            var recipients = Constants.ConfigSettings.SupportTeamEmailRecipients;
            var to         = new MailAddress(recipients.First());
            var cc         = new MailAddressCollection();

            foreach (var recipient in recipients.Skip(1))
            {
                cc.Add(new MailAddress(recipient));
            }

            //AppGlobal.EmailQueue.AddToSendQueue(
            //    TemplatedEmail.EmailMessage(
            //        to,
            //        cc,
            //        null,
            //        template,
            //        parameters));

            var emailMessage = TemplatedEmail.EmailMessage(
                to,
                cc,
                null,
                template,
                parameters);

            var response = SfaSendGridClient.SendGridEmailMessage(emailMessage, null, true);
        }
Beispiel #4
0
 /// <summary>
 /// Create an EmailMessage based on a template.
 /// </summary>
 /// <param name="userId">The UserID to sent the email to.</param>
 /// <param name="emailTemplate">The <see cref="Constants.EmailTemplates"/> to send.</param>
 /// <param name="parameters">A list of <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailParameter"/>s, or null for none.</param>
 /// <param name="overrideRecipientText">n option text to add when the override recipient option is in use.  Leave blank tp get text from language sub-system</param>
 /// <returns>A <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailMessage"/>.</returns>
 public static EmailMessage EmailMessage(string userId, Constants.EmailTemplates emailTemplate,
                                         List <EmailParameter> parameters = null, String overrideRecipientText = "")
 {
     return(EmailMessage(userId, null, emailTemplate, parameters, overrideRecipientText));
 }
Beispiel #5
0
        /// <summary>
        /// Create an EmailMessage based on a template.
        /// </summary>
        /// <param name="to">The MailAddress to sent the email to.</param>
        /// <param name="cc">A collection of email addresses to carbon copy the message to.</param>
        /// <param name="from">The MailAddress to sent the email from, or NULL to use the site defaults.</param>
        /// <param name="emailTemplate">The <see cref="Constants.EmailTemplates"/> to send.</param>
        /// <param name="parameters">A list of <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailParameter"/>s, or null for none.</param>
        /// <param name="overrideRecipientText">n option text to add when the override recipient option is in use.  Leave blank tp get text from language sub-system</param>
        /// <returns>A <see cref="TribalTechnology.InformationManagement.Net.Mail.EmailMessage"/>.</returns>
        public static EmailMessage EmailMessage(MailAddress to, MailAddressCollection cc, MailAddress @from, Constants.EmailTemplates emailTemplate, List <EmailParameter> parameters, String overrideRecipientText = "")
        {
            if (String.IsNullOrWhiteSpace(overrideRecipientText))
            {
                overrideRecipientText = AppGlobal.Language.GetText("TemplatedEmail_EmailOverride_FormatString", "<p>This email was originally sent to {0}:<p>{1}");
            }

            var overrideRecipient = OverrideRecipient(to);
            var settings          = new ConfigurationSettings();

            if (@from == null)
            {
                @from = new MailAddress(settings.AutomatedFromEmailAddress,
                                        settings.AutomatedFromEmailName);
            }

            var @base = GetBaseTemplate();

            EmailTemplate template = (EmailTemplate)CacheManagement.CacheHandler.Get(CacheKey((int)emailTemplate));

            // If items have been removed from cache then read them from the database
            if (@base == null || template == null)
            {
                ProviderPortalEntities db = new ProviderPortalEntities();
                @base    = db.EmailTemplates.Find((Int32)Constants.EmailTemplates.Base);
                template = db.EmailTemplates.Find((Int32)emailTemplate);
            }

            EmailMessage  email;
            StringBuilder sbOriginalRecipients = new StringBuilder();

            if (overrideRecipient)
            {
                var recipients = Constants.ConfigSettings.EmailOverrideRecipients;
                var newTo      = new MailAddress(recipients.First());
                email = new EmailMessage(newTo, @from);
                if (recipients.Count() > 1)
                {
                    email.CC.Add(String.Join(",", recipients.Skip(1)));
                }
                sbOriginalRecipients.AppendFormat("{0} ({1})", to.DisplayName, to.Address);
                if (cc != null)
                {
                    foreach (var ma in cc)
                    {
                        sbOriginalRecipients.AppendFormat(", {0} ({1})", ma.DisplayName, ma.Address);
                    }
                }
            }
            else
            {
                email = new EmailMessage(to, @from);
            }
            email.Subject = @base.Subject;
            email.Body    = overrideRecipient
                ? String.Format(
                overrideRecipientText,
                sbOriginalRecipients, @base.HtmlBody)
                : @base.HtmlBody;
            email.Priority =
                template.Priority == 1
                    ? MailPriority.High
                    : template.Priority == 2
                        ? MailPriority.Normal
                        : MailPriority.Low;
            email.IsBodyHtml = true;
            if (cc != null && !overrideRecipient)
            {
                foreach (var ma in cc)
                {
                    email.CC.Add(ma);
                }
            }

            parameters = parameters ?? new List <EmailParameter>();
            if (parameters.All(k => k.Key != "%SUBJECT%"))
            {
                parameters.Add(new EmailParameter("%SUBJECT%", template.Subject));
            }
            if (parameters.All(k => k.Key != "%NAME%"))
            {
                parameters.Add(new EmailParameter("%NAME%", to.DisplayName));
            }
            if (parameters.All(k => k.Key != "%HTMLBODY%"))
            {
                parameters.Add(new EmailParameter("%HTMLBODY%", template.HtmlBody));
            }
            if (parameters.All(k => k.Key != "%TEXTBODY%"))
            {
                parameters.Add(new EmailParameter("%TEXTBODY%", template.TextBody));
            }

            foreach (var parameter in parameters)
            {
                email.AddEmailParameter(parameter.Key, parameter.Value);
            }

            // De-reference master template parameters
            email.Subject = email.SubjectWithKeysToValue;
            email.Body    = email.BodyWithKeysToValue;

            return(email);
        }