Beispiel #1
0
    public EmailSenderFactoryService(ConfigService configService)
    {
        _senderInstance = null;

        var useSmtp = configService.GetBool(ConfigSettings.UseSmtp);

        if (useSmtp)
        {
            var smtp = new EmailSmtpService(configService);

            if (smtp.IsValid)
            {
                _senderInstance = smtp;
            }
            else
            {
                Logging.LogError("SMTP email provider selected but no valid SMTP settings configured.");
            }
        }
        else
        {
            var sendGrid = new EmailSendGridService(configService);

            if (sendGrid.IsValid)
            {
                _senderInstance = sendGrid;
            }
            else
            {
                Logging.LogError("SendGrid email provider selected but no valid SendGrid settings configured.");
            }
        }
    }
Beispiel #2
0
        private static void SendEmail(EmailMessage emailMessage)
        {
            IEmailService emailService = new EmailSendGridService();

            Console.WriteLine("Sending email...");

            emailService.SendEmailAsync(emailMessage).Wait();

            Console.WriteLine("Email has been sent");
        }
Beispiel #3
0
        public async Task SimplePlaintextEmail()
        {
            try
            {
                var emailConfig = Options.Create(new EmailConfig()
                {
                    ApiKey = "toto"
                });
                EmailSendGridService emailService = new EmailSendGridService(emailConfig);

                await emailService.SendAsync(new MailMessage()
                {
                    Body        = "Test pas très Unitaire",
                    Destination = "*****@*****.**",
                    Subject     = "Test pas très Unitaire"
                });
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }