示例#1
0
        public void Execute(string apiKey, string subject, string message, string email)
        {
            Configuration.Default.AddApiKey("api-key", apiKey);
            // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
            // Configuration.Default.AddApiKeyPrefix("api-key", "Bearer");
            // Configure API key authorization: partner-key
            Configuration.Default.AddApiKey("partner-key", apiKey);
            // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
            // Configuration.Default.AddApiKeyPrefix("partner-key", "Bearer");

            var apiInstance   = new SMTPApi();
            var sendSmtpEmail = new SendSmtpEmail(sender: new SendSmtpEmailSender("No-Reply", "*****@*****.**"),
                                                  to: new List <SendSmtpEmailTo>()
            {
                new SendSmtpEmailTo(email, "Verify")
            },
                                                  htmlContent: message, subject: subject);

            try
            {
                // Send a transactional email
                CreateSmtpEmail result = apiInstance.SendTransacEmail(sendSmtpEmail);
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling SMTPApi.SendTransacEmail: " + e.Message);
            }

            //return true;
        }
        public async Task SendRegistrationSucceededMail(string toMail, string name, string username, string password)
        {
            //Set receipient
            List <SendSmtpEmailTo> To = new List <SendSmtpEmailTo>();

            To.Add(new SendSmtpEmailTo(toMail, name));

            //Define dummy content
            string HtmlContent = null;
            string TextContent = null;
            string Subject     = null;

            //Set mail specific settings
            SendSmtpEmailReplyTo ReplyTo = senderReplyToMail;
            object parameters            = new RegistrationMailModel
            {
                name           = name,
                username       = username,
                password       = password,
                editAccountUri = System.Environment.GetEnvironmentVariable("EditAccountBaseUri") + $"?userid={username}&eMail={toMail}",
            };


            try
            {
                var             sendSmtpEmail = new SendSmtpEmail(senderMail, To, null, null, HtmlContent, TextContent, Subject, ReplyTo, null, null, welcomeMailTemplateId, parameters);
                CreateSmtpEmail result        = await apiInstance.SendTransacEmailAsync(sendSmtpEmail);
            }
            catch (Exception e)
            {
                throw new Exception("Something went wrong while sending Mail", e);
            }
        }
        public async Task SendEMail(string subject, string toMail, string content)
        {
            //Set receipient
            List <SendSmtpEmailTo> To = new List <SendSmtpEmailTo>();

            To.Add(new SendSmtpEmailTo(toMail));

            //Create Dummy Bcc and Cc
            var Bcc = new List <SendSmtpEmailBcc>();
            var Cc  = new List <SendSmtpEmailCc>();

            string HtmlContent           = content;
            string TextContent           = null;
            string Subject               = subject;
            SendSmtpEmailReplyTo ReplyTo = senderReplyToMail;

            try
            {
                var             sendSmtpEmail = new SendSmtpEmail(senderMail, To, Bcc, Cc, HtmlContent, TextContent, Subject, ReplyTo);
                CreateSmtpEmail result        = await apiInstance.SendTransacEmailAsync(sendSmtpEmail);
            }
            catch (Exception e)
            {
                throw new Exception("Something went wrong while sending Mail", e);
            }
        }
示例#4
0
        public async Task SendEmailAsync(string senderName, string senderEmail, string topic, string contentHTML, string recieverMail, string recieverName = "user")
        {
            var subject     = topic;
            var htmlContent = contentHTML;
            var sender      = new SendSmtpEmailSender(senderName, senderEmail);
            var to          = new List <SendSmtpEmailTo> {
                new SendSmtpEmailTo(recieverMail, recieverName)
            };
            var email = new SendSmtpEmail(sender, to, null, null, htmlContent, null, subject);

            try
            {
                CreateSmtpEmail result = await apiInstance.SendTransacEmailAsync(email);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine("ERROR SMTP" + ex.Message);
            }
        }
        private async Task <string> SendViaSendInBlue(SendSmtpEmail msg)
        {
            var configuration = new Configuration();

            configuration.AddApiKey("api-key", emailSettings.SendInBlueSettings.ApiKey);
            var apiInstance = new SMTPApi(configuration);

            try
            {
                // Send a transactional email
                CreateSmtpEmail result = await apiInstance.SendTransacEmailAsync(msg);

                logger.LogDebug("SendInBlue sent email {Result}", result.MessageId);
                return(result.MessageId);
            }
            catch (Exception e)
            {
                throw new SendInBlueException("Exception when calling SMTPApi.SendTransacEmailAsync: ", e);
            }
        }