Esempio n. 1
0
        public async Task Smtp_SendTemplateMail_ShouldSend()
        {
            SmtpCredentials credentials = new("smtp.mailtrap.io", "587", "false", "true", "d3538ae47a016d", "d4add3690c408c");

            EmailComposer <TestMailModel> composer = new();
            EmailRequest <TestMailModel>  request  = composer
                                                     .SetModel(new TestMailModel {
                Email = "*****@*****.**", Name = "Guy Gadbois"
            })
                                                     .SetSubject("Hello world")
                                                     .SetFrom("*****@*****.**", "Facteur")
                                                     .SetTo("*****@*****.**")
                                                     .SetCc("*****@*****.**")
                                                     .SetBcc("*****@*****.**")
                                                     .Build();

            IMailer mailer = new SmtpMailer(credentials);

            IMailBodyBuilder builder          = new MailBodyBuilder();
            EmailRequest     populatedRequest = await builder
                                                .UseProvider(new AppDirectoryTemplateProvider("Templates", ".sbnhtml"))
                                                .UseResolver(new ViewModelTemplateResolver())
                                                .UseCompiler(new ScribanCompiler())
                                                .BuildAsync(request);

            await mailer.SendMailAsync(populatedRequest);
        }
Esempio n. 2
0
        public async Task Smtp_SendTemplateMail_WithAttachments_ShouldSend()
        {
            SmtpCredentials credentials = new("smtp.mailtrap.io", "587", "false", "true", "d3538ae47a016d", "d4add3690c408c");

            byte[] txtBytes = File.ReadAllBytes("Attachments\\Attachment.txt");
            byte[] pdfBytes = File.ReadAllBytes("Attachments\\Attachment.pdf");

            List <Attachment> attachments = new()
            {
                new Attachment()
                {
                    ContentBytes = txtBytes, Name = "Attachment.txt"
                },
                new Attachment()
                {
                    ContentBytes = pdfBytes, Name = "Attachment.pdf"
                }
            };

            EmailComposer <TestMailModel> composer = new();
            EmailRequest <TestMailModel>  request  = composer
                                                     .SetModel(new TestMailModel {
                Email = "*****@*****.**", Name = "Guy Gadbois"
            })
                                                     .SetSubject("Hello world")
                                                     .SetFrom("*****@*****.**")
                                                     .SetTo("*****@*****.**")
                                                     .SetCc("*****@*****.**")
                                                     .SetBcc("*****@*****.**")
                                                     .Attach(attachments)
                                                     .Build();

            IMailer mailer = new SmtpMailer(credentials);

            IMailBodyBuilder builder          = new MailBodyBuilder();
            EmailRequest     populatedRequest = await builder
                                                .UseProvider(new AppDirectoryTemplateProvider("Templates", ".sbnhtml"))
                                                .UseResolver(new ViewModelTemplateResolver())
                                                .UseCompiler(new ScribanCompiler())
                                                .BuildAsync(request);

            await mailer.SendMailAsync(populatedRequest);
        }
    }