public static void SendTemplatedEmailExample() { // Creating a Tribal Email message object from a template. // You can specify a user ID or a MailAddress to send the email to // Optionally specify a from address, if none is specified the default site from name and email will be used // Optionally specify a list of parameters var userId = Permission.GetCurrentUserId(); EmailMessage email = TemplatedEmail.EmailMessage(userId, Constants.EmailTemplates.Base); // Use the AddEmailParameter method to set the replacement text, example email.AddEmailParameter("%HTMLBODY%", "Hello world"); // Send the email, the email is added to the queue and processed asynchronously so control is returned immediately to the caller, and the event log gets a log of the email sent with the parameters // The email is sent immediately AppGlobal.EmailQueue.AddToSendQueue(email); // Or all-in-one AppGlobal.EmailQueue.AddToSendQueue( TemplatedEmail.EmailMessage( userId, Constants.EmailTemplates.Base, new List <EmailParameter> { new EmailParameter("%HTMLBODY%", "Hello World") })); }
/// <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); }