示例#1
0
        public virtual void SendAdminEmail(string subject, string message)
        {
            base.ExecuteMethod("SendAdminEmail", delegate()
            {
                try
                {
                    IEmailTransport transport = this.IFoundation.SafeResolve <IEmailTransport>();
                    if (transport != null)
                    {
                        string recipientEmail = this.API.Direct.GlobalSettings.GetValueOrDefault("EmailTarget_Admin", "*****@*****.**");
                        string fromEmail      = this.API.Direct.GlobalSettings.GetValueOrDefault("EmailFromEmail_System", "*****@*****.**");
                        string fromName       = this.API.Direct.GlobalSettings.GetValueOrDefault("EmailFromName_System", "Stencil Platform");

                        EmailRecipient recipient  = new EmailRecipient(recipientEmail);
                        IEmail email              = transport.CreateEmail();
                        email.FromEmail           = fromEmail;
                        email.FromName            = fromName;
                        email.InternalMessageType = "AdminMessage";
                        email.InternalTypeID      = "Admin";
                        email.HTMLBody            = message;
                        email.Subject             = subject;

                        transport.SendEmail(email, recipient, false);
                    }
                }
                catch (Exception ex)
                {
                    base.IFoundation.LogError(ex, "SendAdminEmail");
                }
            });
        }
示例#2
0
        /// <summary>
        /// Construct a sink emailing with the specified details.
        /// </summary>
        /// <param name="emailConfig">Connection information used to construct the SMTP client and mail messages.</param>
        /// <param name="textFormatter">Supplies culture-specific formatting information, or null.</param>
        /// <param name="subjectLineFormatter">Supplies culture-specific formatting information, or null.</param>
        /// <exception cref="System.ArgumentNullException">connectionInfo</exception>
        public EmailSink(EmailConfig emailConfig, ITextFormatter textFormatter, ITextFormatter subjectLineFormatter)
        {
            if (emailConfig == null)
            {
                throw new ArgumentNullException(nameof(emailConfig));
            }

            _emailConfig          = emailConfig;
            _emailTransport       = _emailConfig.CreateEmailTransport();
            _textFormatter        = textFormatter;
            _subjectLineFormatter = subjectLineFormatter;
        }
示例#3
0
        public virtual void SendEmail(EmailFormat format, string messageTypeID, string messageTypeCategory, string recipientEmail, Dictionary <string, string> tokenValues, string[] ccRecipients = null)
        {
            base.ExecuteMethod("PrepareAndSend", delegate()
            {
                IEmailTransport transport = this.IFoundation.SafeResolve <IEmailTransport>();
                if (transport != null)
                {
                    string templateKey = "EmailTemplate_" + format.ToString();
                    string subjectKey  = "EmailTemplate_" + format.ToString() + "_Subject";

                    string bodyTemplate = this.Cache.PerLifetime(templateKey, delegate()
                    {
                        return(this.API.Direct.GlobalSettings.GetValueOrDefault(templateKey, ""));
                    });
                    string subjectTemplate = this.Cache.PerLifetime(subjectKey, delegate()
                    {
                        return(this.API.Direct.GlobalSettings.GetValueOrDefault(subjectKey, ""));
                    });

                    if (string.IsNullOrEmpty(bodyTemplate) || string.IsNullOrEmpty(subjectTemplate))
                    {
                        this.SendAdminEmail("Flawed Configuration", "No Email Subject, Body Template found for: " + format.ToString());
                        return;
                    }

                    EmailRecipient recipient = new EmailRecipient(recipientEmail);
                    IEmail email             = transport.CreateEmail();
                    email.FromEmail          = this.Cache.PerLifetime("Email_FromEmail", delegate()
                    {
                        return(this.API.Direct.GlobalSettings.GetValueOrDefault("EmailFromEmail_Standard", "*****@*****.**"));
                    });
                    email.FromName = this.Cache.PerLifetime("Email_FromName", delegate()
                    {
                        return(this.API.Direct.GlobalSettings.GetValueOrDefault("EmailFromName_Standard", "Stencil"));
                    });
                    email.InternalMessageType = messageTypeCategory;
                    email.InternalTypeID      = messageTypeID;
                    email.HTMLBody            = this.ProcessTemplate(bodyTemplate, recipientEmail, tokenValues);
                    email.Subject             = this.ProcessTemplate(subjectTemplate, recipientEmail, tokenValues);
                    if (ccRecipients != null && ccRecipients.Length > 0)
                    {
                        if (email.ExtraData == null)
                        {
                            email.ExtraData = new Dictionary <string, string>();
                        }
                        email.ExtraData["cc"] = string.Join(";", ccRecipients);
                    }

                    if (string.IsNullOrEmpty(email.Subject))
                    {
                        email.Subject = "Information";
                    }
                    if (tokenValues.ContainsKey("FromName"))
                    {
                        email.FromName = tokenValues["FromName"];
                    }
                    if (tokenValues.ContainsKey("FromEmail"))
                    {
                        email.FromEmail = tokenValues["FromEmail"];
                    }

                    transport.SendEmail(email, recipient, false);
                }
            });
        }
        public BaseEmailSender(ITemplateEngine engine, IEmailTransport sender, ITextTranslatorFactory translatorFactory) {
			_transport = sender;
			_templateEngine = engine;
            _translatorFactory = translatorFactory;
		}
        public OrderConfirmationEmailSender(ITemplateEngine engine, IEmailTransport sender, ITextTranslatorFactory translatorFactory) : base(engine, sender, translatorFactory) {
		}
 public NotificationService(IEmailTransport emailTransport)
 {
     _emailTransport = emailTransport;
 }