Пример #1
0
        public void SendEmailRequest(TopicMessage topicMessage = null)
        {
            if (topicMessage != null)
            {
                BuildMessage(topicMessage);
            }

            using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USEast1))
            {
                var sendRequest = new SendEmailRequest
                {
                    Source      = Globals.SENDER_ADDRESS,
                    Destination = new Destination
                    {
                        ToAddresses =
                            new List <string> {
                            Globals.RECEIVER_ADDRESS
                        }
                    },
                    Message = new Message
                    {
                        Subject = new Content(this.Subject),
                        Body    = new Body
                        {
                            Html = new Content
                            {
                                Charset = "UTF-8",
                                Data    = this.HtmlBody
                            },
                            Text = new Content
                            {
                                Charset = "UTF-8",
                                Data    = this.TextBody
                            }
                        }
                    },
                    // If you are not using a configuration set, comment
                    // or remove the following line
                    //ConfigurationSetName = Globals.CONFIG_SET
                };
                try
                {
                    Console.WriteLine("Sending email using Amazon SES...");
                    var response = client.SendEmail(sendRequest);
                    Console.WriteLine("The email was sent successfully.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("The email was not sent.");
                    Console.WriteLine("Error message: " + ex.Message);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var          objConsumer = new MessageConsumer();
            var          objEmail    = new SendEmail();
            TopicMessage message     = new TopicMessage();

            while (true)
            {
                Console.WriteLine("... Wait...\n");

                message.Data.Add(objConsumer.ReceiveMessageQueue());

                objEmail.SendEmailRequest(message);
            }
        }
Пример #3
0
        public void BuildMessage(TopicMessage topicMessage)
        {
            this.Subject = "Alert from Producer!";
            string bodyMessage = "";

            foreach (var item in topicMessage.Data)
            {
                bodyMessage += string.Format(" <li> {0}: {1} </li> ", item.ReceivedTime.ToString(), item.Message);
            }

            this.HtmlBody = string.Format(@"<html>
                <head></head>
                <body>
                    <h2>Status update</h2>
                    <ul> 
                        {0} 
                    </ul>
                </body>
            </html>", bodyMessage);

            this.TextBody = "E-mail provider unsupported message body";
        }