Exemplo n.º 1
0
        //methods
        public virtual async Task <ProcessingResult> Send(SignalDispatch <TKey> item)
        {
            EmailDispatch <TKey> signal = (EmailDispatch <TKey>)item;

            using (var client = new AmazonSimpleEmailServiceClient(_credentials.AwsAccessKey,
                                                                   _credentials.AwsSecretKey, _credentials.RegionEndpoint))
            {
                SendEmailRequest  request  = CreateAmazonRequest(signal);
                SendEmailResponse response = null;
                response = await client.SendEmailAsync(request);
            }

            return(ProcessingResult.Success);
        }
Exemplo n.º 2
0
        public void EmailDispatchTemplate_BuildTest(string language, string expectedText)
        {
            //arrange
            var emailTemplate = new EmailDispatchTemplate <long>()
            {
                BodyProvider    = new ResourceTemplate(typeof(ContentRes), "ContentKey"),
                BodyTransformer = new ReplaceTransformer()
            };

            var settings = new EventSettings <long>()
            {
                Subscription = new DAL.Parameters.SubscriptionParameters
                {
                    CategoryId = 1
                }
            };
            var signalEvent    = new SignalEvent <long>();
            var subscriberList = new List <Subscriber <long> >()
            {
                new Subscriber <long>()
                {
                    SubscriberId = 2,
                    Language     = language
                }
            };
            var templateData = new List <TemplateData>()
            {
                new TemplateData(
                    keyValueModel: new Dictionary <string, string>()
                {
                    { "key", "value" }
                },
                    objectModel: null,
                    language: language
                    )
            };

            //act
            List <SignalDispatch <long> > actual = emailTemplate.Build(settings, signalEvent, subscriberList, templateData);

            //assert
            EmailDispatch <long> item = (EmailDispatch <long>)actual.First();

            Assert.AreEqual(expectedText, item.MessageBody);
        }
Exemplo n.º 3
0
        protected virtual SendEmailRequest CreateAmazonRequest(EmailDispatch <TKey> message)
        {
            // Construct an object to contain the recipient address.
            Destination destination = new Destination();

            destination.ToAddresses = new List <string>()
            {
                message.ReceiverAddress
            };

            // Create the subject and body of the message.
            Content contentSubject = new Content(message.MessageSubject);
            Content contentBody    = new Content(message.MessageBody);

            Body body = new Body();

            if (message.IsBodyHtml)
            {
                body.Html = contentBody;
            }
            else
            {
                body.Text = contentBody;
            }

            // Create a message with the specified subject and body.
            Message mailMessage = new Message(contentSubject, body);

            // Assemble the email.
            SendEmailRequest request = new SendEmailRequest()
            {
                Source      = SenderAddress,
                Destination = destination,
                Message     = mailMessage
            };

            return(request);
        }