Ejemplo n.º 1
0
        public async Task <SendTemplatedEmailResponse> SendTemplate(string templatename,
                                                                    string name,
                                                                    string url,
                                                                    List <string> to)
        {
            _sendtemplaterequest = new SendTemplatedEmailRequest()
            {
                SourceArn    = "arn:aws:ses:us-east-1:775734958315:identity/[email protected]",
                Source       = "*****@*****.**",
                Template     = templatename,
                TemplateData = $"{{ \"username\":\"{name}\", \"urlinfo\": \"{url}\" }}",
                Destination  = new Destination
                {
                    ToAddresses = to
                }
            };
            try
            {
                _sendtemplateresponse = await _Client.SendTemplatedEmailAsync(_sendtemplaterequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Data: {ex.Data}");
                Console.WriteLine($"Source: {ex.Source}");
                Console.WriteLine($"Message: {ex.Message}");
            }

            return(_sendtemplateresponse);
        }
Ejemplo n.º 2
0
        public async Task <EmailResponse> SendEmailWithTemplate(EmailTemplateRequest emailWithTemplateRequest)
        {
            EmailResponse emailResponse = new EmailResponse();

            using var client = new AmazonSimpleEmailServiceClient(EmailConfiguration.AccessKeyId, EmailConfiguration.AccessSecretKey, RegionEndpoint.USEast1);

            var sendRequest = new SendTemplatedEmailRequest
            {
                Source      = EmailConfiguration.SenderAddress,
                Destination = new Destination
                {
                    ToAddresses = emailWithTemplateRequest.Receivers
                },
                Template     = emailWithTemplateRequest.Template,
                TemplateData = JsonSerializer.Serialize(emailWithTemplateRequest.Data)
            };

            try
            {
                await client.SendTemplatedEmailAsync(sendRequest);

                emailResponse.Success = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("The email was not sent.");
                Console.WriteLine("Error message: " + ex.Message);
                emailResponse.Success = false;
            }

            client.Dispose();

            return(emailResponse);
        }
Ejemplo n.º 3
0
        public async Task <SendTemplatedEmailResponse> SendTemplate(string templatename,
                                                                    List <string> to, List <string> cc, List <string> bcc,
                                                                    string from, string jsontempvariables)
        {
            _sendtemplaterequest = new SendTemplatedEmailRequest()
            {
                Source       = from,
                Template     = templatename,
                TemplateData = jsontempvariables,
                Destination  = new Destination
                {
                    ToAddresses  = to,
                    CcAddresses  = cc,
                    BccAddresses = bcc
                }
            };
            try
            {
                _sendtemplateresponse = await _Client.SendTemplatedEmailAsync(_sendtemplaterequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Data: {ex.Data}");
                Console.WriteLine($"Source: {ex.Source}");
                Console.WriteLine($"Message: {ex.Message}");
                _sendtemplateresponse = new SendTemplatedEmailResponse {
                    HttpStatusCode = System.Net.HttpStatusCode.NoContent,
                    MessageId      = ex.Message
                };
            }

            return(_sendtemplateresponse);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send a marketing welcome email to a user who has signed up to recieve marketing emails.
        /// </summary>
        /// <param name="mUser">Marketing user information</param>
        /// <returns>None.</returns>
        public async Task SendMarketWelcome(MarketingUser mUser)
        {
            // Create information for a new marketing email
            var data = new MarketingWelcomeEmail
            {
                User            = mUser.Name,
                Email           = mUser.Email,
                UnsubscribeLink = string.Format("https://patrons.at/email/unsubscribe/{0}", await _database.CreateMarketingUserUnsubscribeLink(mUser))
            };

            // Convert data to a JSON string.
            string jsonData = JsonSerializer.Serialize <MarketingWelcomeEmail>(data);

            // Required template information:
            //  * name: user name
            //  * email: email address
            //  * unsubscribe_link: unsubscribe link
            var emailRequest = new SendTemplatedEmailRequest()
            {
                Source      = "*****@*****.**",
                Destination = new Destination
                {
                    ToAddresses = new List <string> {
                        mUser.Email
                    }
                },
                Template     = "marketing-welcome",
                TemplateData = jsonData,
            };

            // Send the email.
            await _emailClient.SendTemplatedEmailAsync(emailRequest);
        }
Ejemplo n.º 5
0
        public async Task SendEmailAsync(string to, string attachmentPath)
        {
            using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.EUWest1))
            {
                var request = new SendTemplatedEmailRequest
                {
                    Source      = senderAddress,
                    Destination = new Destination
                    {
                        ToAddresses = new List <string> {
                            to
                        }
                    },
                    Template     = "cv_response_email_template",
                    TemplateData = JsonConvert.SerializeObject(new { sourceEmail = to })
                };

                try
                {
                    context.Logger.LogLine("Sending email using Amazon SES...");
                    var response = await client.SendTemplatedEmailAsync(request);

                    context.Logger.LogLine("The email was sent successfully.");
                }
                catch (Exception ex)
                {
                    context.Logger.LogLine($"Error while sending email: {ex.Message}");
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <bool> SendEmailAsync(EmailProperties emailProperties)
        {
            //const string configset = "ConfigSet";
            var          status             = false;
            const string awsAccessKey       = "AKIAJ4IK5ITYGVQ6NICA";
            const string awsAccessSecretKey = "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";

            using (var awsClient = new AmazonSimpleEmailServiceClient(awsAccessKey, awsAccessSecretKey, RegionEndpoint.USEast1))
            {
                var request = new SendEmailRequest
                {
                    Source      = _emailSettings.SmtpEmail,
                    Destination = new Destination()
                    {
                        ToAddresses = emailProperties.ReceipentsEmail
                    },
                    Message = new Message()
                    {
                        Subject = new Content(emailProperties.Subject),
                        Body    = new Body()
                        {
                            Html = new Content
                            {
                                Charset = "UTF-8",
                                Data    = "This message body contains HTML formatting. It can, for example, contain links like this one: <a href ='http://docs.aws.amazon.com/ses/latest/DeveloperGuide\' target = '\'_blank\"> Amazon SES Developer Guide </a>."
                            },
                            Text = new Content()
                            {
                                Charset = "UTF-8",
                                Data    = emailProperties.Body
                            }
                        }
                    }
                };

                var templatedEmailRequest = new SendTemplatedEmailRequest
                {
                    Source      = _emailSettings.SmtpEmail,
                    Destination = new Destination()
                    {
                        ToAddresses = emailProperties.ReceipentsEmail
                    },
                    Template     = "withButtonTemplate",
                    TemplateData = "{\"subject\":\"" + emailProperties.Subject + "\"}"
                };

                var response = await awsClient.SendEmailAsync(request);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    status = true;
                }
            }


            return(status);
        }
Ejemplo n.º 7
0
        public static void SendTemplatedEmail(this ISendMailService svc, EmailMessage email)
        {
            var req = new SendTemplatedEmailRequest
            {
                Body = new SendTemplatedEmailRequestBody
                {
                    email = email
                }
            };

            svc.SendTemplatedEmail(req);
        }
Ejemplo n.º 8
0
        protected override async Task <IResponse> SendEmailAsync(IEmail email)
        {
            IResponse res = new Response();

            using (var client = new AmazonSimpleEmailServiceClient(
                       _settings.GetConfigSetting <string>(SettingKeys.Messaging.Aws.Ses.AccessKey),
                       _settings.GetConfigSetting <string>(SettingKeys.Messaging.Aws.Ses.SecretKey),
                       RegionEndpoint.USWest2))
            {
                var sendTemplatedEmail = new SendTemplatedEmailRequest
                {
                    Source      = email.From,
                    Destination = new Destination
                    {
                        ToAddresses = new List <string>
                        {
                            email.To
                        },
                        BccAddresses = email.Bcc == null ? new List <string>() : new List <string> {
                            email.Bcc
                        },
                    },
                    Template             = email.TemplateName,
                    ConfigurationSetName = String.IsNullOrEmpty(email.ConfigurationSetName) ? "" : email.ConfigurationSetName,
                    TemplateData         = JsonConvert.SerializeObject(email.Variables)
                };

                SendTemplatedEmailResponse response;
                try
                {
                    response = await client.SendTemplatedEmailAsync(sendTemplatedEmail);

                    var result = response.HttpStatusCode.ToString();
                    if (result == "OK")
                    {
                        res.Success = true;
                    }
                    else
                    {
                        res.ErrorMessage = result;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(LogCategory.Error, ex);
                    res.Success = false;
                }
                return(res);
            }
        }
Ejemplo n.º 9
0
        protected override async Task <IResponse> SendEmailAsync(IEmail email)
        {
            SendTemplatedEmailResponse response;
            IResponse res = new Response {
                Success = true
            };
            List <string> ToAddresses = new List <string>();

            using (var client = new AmazonSimpleEmailServiceClient(
                       _settings.GetConfigSetting <string>(SettingKeys.Messaging.Aws.Ses.AccessKey),
                       _settings.GetConfigSetting <string>(SettingKeys.Messaging.Aws.Ses.SecretKey),
                       RegionEndpoint.USWest2))
            {
                SendTemplatedEmailRequest sendTemplatedEmail
                    = new SendTemplatedEmailRequest
                    {
                    Source      = email.From,
                    Destination = new Destination
                    {
                        ToAddresses =
                            new List <string> {
                            email.To
                        }
                    },
                    Template             = email.TemplateName,
                    ConfigurationSetName = String.IsNullOrEmpty(email.ConfigurationSetName) ? "" : email.ConfigurationSetName,
                    TemplateData         = JsonConvert.SerializeObject(email.Variables)
                    };

                try
                {
                    response = await client.SendTemplatedEmailAsync(sendTemplatedEmail);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                string result = response.HttpStatusCode.ToString();
                client.Dispose();
                if (result == "OK")
                {
                    return(res);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Ejemplo n.º 10
0
 SendTemplatedEmailResponse ISendMailService.SendTemplatedEmail(SendTemplatedEmailRequest request)
 {
     return _client.Invoke(s => s.SendTemplatedEmail(request));
 }