/// <summary>
        /// Register Coravel's mailer using the Custom Mailer.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="sendMailAsync"></param>
        public static void AddCustomMailer(this IServiceCollection services, IConfiguration config, CustomMailer.SendAsyncFunc sendMailAsync)
        {
            var           globalFrom = GetGlobalFromRecipient(config);
            RazorRenderer renderer   = RazorRendererFactory.MakeInstance(config);
            var           mailer     = new CustomMailer(renderer, sendMailAsync, globalFrom);

            services.AddSingleton <IMailer>(mailer);
        }
Example #2
0
 public void Setup()
 {
     TearDown();
     using (var db = new MailDemonDatabase())
     {
         db.Initialize();
     }
     viewRenderer = new RazorRenderer(Path.Combine(Directory.GetCurrentDirectory(), "../../.."));
 }
Example #3
0
        /// <summary>
        /// Register Coravel's mailer using the File Log Mailer - which sends mail to a file.
        /// Useful for testing.
        /// </summary>
        /// <param name="services"></param>
        public static IServiceCollection AddFileLogMailer(this IServiceCollection services, IConfiguration config)
        {
            var           globalFrom = GetGlobalFromRecipient(config);
            RazorRenderer renderer   = RazorRendererFactory.MakeInstance(config);
            var           mailer     = new FileLogMailer(renderer, globalFrom);

            services.AddSingleton <IMailer>(mailer);
            return(services);
        }
Example #4
0
 public void Setup()
 {
     TearDown();
     using (var db = new MailDemonDatabase())
     {
         db.Initialize();
     }
     viewRenderer = new RazorRenderer(null, Directory.GetCurrentDirectory(),
                                      Assembly.GetExecutingAssembly());
 }
        public void TestRazorRenderWithNullModel()
        {
            //Assign
            var razorRenderer = new RazorRenderer(null);

            //Act
            var ex = Assert.Throws <ArgumentNullException>(() => razorRenderer.Render <MyClass>("coucou", null));

            //Assert
            ex.Should().NotBeNull("An exception should be throw");
        }
Example #6
0
        public EmailSender(IOptions <EmailSettings> emailOptions)
        {
            _emailSettings = emailOptions.Value;

            var sender = new MailgunSender(
                _emailSettings.Domain, // Mailgun Domain
                _emailSettings.ApiKey  // Mailgun API Key
                );

            var razorRenderer = new RazorRenderer();


            emailSender = new Email(razorRenderer, sender);
        }
Example #7
0
        internal async Task SendAsync(RazorRenderer renderer, IMailer mailer)
        {
            this.Build();

            string message = await this.BuildMessage(renderer, mailer).ConfigureAwait(false);

            await mailer.SendAsync(
                message,
                this._subject,
                this._to,
                this._from,
                this._replyTo,
                this._cc,
                this._bcc
                ).ConfigureAwait(false);
        }
        public void TestRazorRenderWithEmptyTemplatePath()
        {
            //Assign
            var myClass = new MyClass()
            {
                Prop1 = 1,
                Prop2 = "Test"
            };
            var razorRenderer = new RazorRenderer(null);

            //Act
            var ex = Assert.Throws <ArgumentNullException>(() => razorRenderer.Render(string.Empty, myClass));

            //Assert
            ex.Should().NotBeNull("An exception should be throw");
        }
        /// <summary>
        /// Register Coravel's mailer using the Smtp Mailer.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="config"></param>
        /// <param name="certCallback"></param>
        public static void AddSmtpMailer(this IServiceCollection services, IConfiguration config, RemoteCertificateValidationCallback certCallback)
        {
            var           globalFrom = GetGlobalFromRecipient(config);
            RazorRenderer renderer   = RazorRendererFactory.MakeInstance(config);
            IMailer       mailer     = new SmtpMailer(
                renderer,
                config.GetValue <string>("Coravel:Mail:Host", ""),
                config.GetValue <int>("Coravel:Mail:Port", 0),
                config.GetValue <string>("Coravel:Mail:Username", ""),
                config.GetValue <string>("Coravel:Mail:Password", ""),
                globalFrom,
                certCallback
                );

            services.AddSingleton <IMailer>(mailer);
        }
Example #10
0
        private async Task <string> BuildMessage(RazorRenderer renderer, IMailer mailer)
        {
            this.BindDynamicProperties();

            if (this._html != null)
            {
                return(this._html);
            }

            if (this._viewPath != null)
            {
                return(await renderer
                       .RenderViewToStringAsync <T>(this._viewPath, this._viewModel)
                       .ConfigureAwait(false));
            }

            throw new NoMailRendererFound(NoRenderFoundMessage);
        }
Example #11
0
        public SmtpMailer(
            RazorRenderer renderer,
            string host,
            int port,
            string username,
            string password,
            MailRecipient globalFrom = null,
            RemoteCertificateValidationCallback certificateCallback = null)
        {
            this._renderer   = renderer;
            this._host       = host;
            this._port       = port;
            this._username   = username;
            this._password   = password;
            this._globalFrom = globalFrom;

            this._certCallback = certificateCallback;
            if (this._certCallback == null)
            {
                this._certCallback = (s, c, h, e) => true; // Allow any cert.
            }
        }
Example #12
0
 internal async Task <string> RenderAsync(RazorRenderer renderer, IMailer mailer)
 {
     this.Build();
     return(await this.BuildMessage(renderer, mailer).ConfigureAwait(false));
 }
Example #13
0
 public Function1(RazorRenderer engine)
 {
     Engine = engine;
 }
Example #14
0
 public FileLogMailer(RazorRenderer renderer, MailRecipient globalFrom)
 {
     this._renderer   = renderer;
     this._globalFrom = globalFrom;
 }
Example #15
0
 public string Render(params Assembly[] assembliesToReference)
 {
     return(RazorRenderer.RenderResource <ProxyMethodModel>(this, "ProxyMethod.tmpl", assembliesToReference));
 }
Example #16
0
 public CustomMailer(RazorRenderer renderer, SendAsyncFunc sendAsyncFunc, MailRecipient globalFrom = null)
 {
     this._renderer      = renderer;
     this._sendAsyncFunc = sendAsyncFunc;
     this._globalFrom    = globalFrom;
 }
Example #17
0
 public string Render()
 {
     return(RazorRenderer.RenderResource <ProxyModel>(this, "Proxy.tmpl", ReferenceAssemblies));
 }