Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string AccessKey= System.Configuration.ConfigurationManager.AppSettings["AccessKey"];
            string SecrectKey = System.Configuration.ConfigurationManager.AppSettings["SecrectKey"];
            Amazon.SimpleEmail.AmazonSimpleEmailServiceClient mailClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient(AccessKey,SecrectKey);
            //var obj = mailClient.GetSendQuota();
            SendEmailRequest request = new SendEmailRequest();
            List<string> toaddress = new List<string>();
            toaddress.Add("*****@*****.**");
            Destination des = new Destination(toaddress);
            request.Destination = des;
            request.Source = "*****@*****.**";
            Amazon.SimpleEmail.Model.Message mes = new Amazon.SimpleEmail.Model.Message();
            mes.Body = new Body(new Content( @"Hiện tại, Windows Phone mới hỗ trợ đến màn hình full HD, do đó để tương thích với màn hình 2K, hệ điều hành chắc chắn phải có bản cập nhật mới. Mặt khác, vi xử lý Snapdragon 805 của Qualcomm được biết sẽ phát hành đại trà vào nửa sau năm nay, nên thời điểm xuất hiện Lumia 1820 dùng vi xử lý này tại MWC 2014 vào tháng Hai sẽ là dấu hỏi lớn.

            Microsoft đã từng nói hãng đã chi tới 2,6 tỉ USD để phát triển cho hệ điều hành Windows Phone. Và năm nay, Microsoft đang có kế hoạch lớn dành cho Windows Phone lẫn Nokia. Do đó, chúng ta hãy cứ hy vọng Lumia 1525 và Lumia 1820 sẽ là bom tấn smartphone được kích hoạt trong 2014 này."));
            mes.Subject = new Content("Test send via amazon");

            request.Message = mes;

            SendEmailResponse response = mailClient.SendEmail(request);
            var messageId = response.SendEmailResult.MessageId;
            /*GetIdentityNotificationAttributesRequest notifyRequest = new GetIdentityNotificationAttributesRequest();
            List<string> iden = new List<string>();
            iden.Add("*****@*****.**"); //iden.Add(response.ResponseMetadata.RequestId);
            notifyRequest.Identities = iden;
            var notify = mailClient.GetIdentityNotificationAttributes(notifyRequest);
            //MessageBox.Show(notify.GetIdentityNotificationAttributesResult.NotificationAttributes["Bounces"].BounceTopic);

            var temp = mailClient.GetSendStatistics();
            MessageBox.Show("Total: "+temp.GetSendStatisticsResult.SendDataPoints.Count+"\nDeliveryAttempts: "+temp.GetSendStatisticsResult.SendDataPoints[265].DeliveryAttempts+"\n"
                + "Complaints: " + temp.GetSendStatisticsResult.SendDataPoints[265].Complaints + "\n"
                + "Bounces: " + temp.GetSendStatisticsResult.SendDataPoints[265].Bounces + "\n"
                + "Rejects: " + temp.GetSendStatisticsResult.SendDataPoints[265].Rejects + "\n");
               // MessageBox.Show("Max24HourSend:" + obj.GetSendQuotaResult.Max24HourSend + "\nMaxSendRate:" + obj.GetSendQuotaResult.MaxSendRate + "\nSentLast24Hours:" + obj.GetSendQuotaResult.SentLast24Hours);

            Amazon.SimpleNotificationService.Model.GetEndpointAttributesRequest endpointRequest = new Amazon.SimpleNotificationService.Model.GetEndpointAttributesRequest();
            Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient notifyClient = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient();
            //string result = notifyClient.GetEndpointAttributes(notify).GetEndpointAttributesResult.ToXML();
            //MessageBox.Show(result);
            */
            Amazon.SQS.AmazonSQSClient client = new Amazon.SQS.AmazonSQSClient(AccessKey, SecrectKey);
            Amazon.SQS.Model.ReceiveMessageRequest SQSrequest = new Amazon.SQS.Model.ReceiveMessageRequest();
            SQSrequest.MaxNumberOfMessages = 10;
            SQSrequest.QueueUrl = "https://sqs.us-east-1.amazonaws.com/063719400628/bounce-queue";
            AmazonQueues.ProcessQueuedBounce(client.ReceiveMessage(SQSrequest));
        }
        public void sendEmailToAuthenticateAUser(Users user)
        {
            try
            {
                System.Collections.Generic.List<string> listColl = new System.Collections.Generic.List<string>();
                ////TODO - Write a simple loop to add the recipents email addresses to the listColl object.
                listColl.Add(user.userName.ToString());

                Amazon.SimpleEmail.AmazonSimpleEmailServiceClient client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient("AKIAJUPAMCIGTBC2ODXQ", "s7PkEfwVmhbzWT5PFeN5CV3ZzSPemgaaxnwa32pp");
                SendEmailRequest mailObj = new SendEmailRequest();

                Destination destinationObj = new Destination(listColl);

                mailObj.Source = "*****@*****.**";
                ////The from email address
                mailObj.ReturnPath = "*****@*****.**";
                ////The email address for bounces
                mailObj.Destination = destinationObj;

                string urlLink = "http://ec2-177-71-137-221.sa-east-1.compute.amazonaws.com/smartaudiocityguide/User/authenticateUser/?hash=" + user.hash;
                ////Create Message
                Amazon.SimpleEmail.Model.Content emailSubjectObj = new Amazon.SimpleEmail.Model.Content("Authentication for Smart Audio City Guide");
                Amazon.SimpleEmail.Model.Content emailBodyContentObj = new Amazon.SimpleEmail.Model.Content(@"<htm>
                <head>
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                <title>Smart Audio City Guide</title>
                </head>
                <body>
                <div>
                    <a> Welcome " + user.name + "to Smart Audio City Guide </a><br/><a>Click on the link to authenticate your account: <a href='"+urlLink+"'>"+ urlLink+ "</a></a></div></body>");

                Amazon.SimpleEmail.Model.Body emailBodyObj = new Amazon.SimpleEmail.Model.Body();
                emailBodyObj.Html = emailBodyContentObj;
                Message emailMessageObj = new Message(emailSubjectObj, emailBodyObj);
                mailObj.Message = emailMessageObj;

                dynamic response2 = client.SendEmail(mailObj);
            }
            catch (Exception)
            {

            }
        }
Ejemplo n.º 3
0
        public static void SendAmazonEmail(MailMessage msg)
        {
            Amazon.SimpleEmail.Model.Content subject = new Amazon.SimpleEmail.Model.Content(msg.Subject);
            Amazon.SimpleEmail.Model.Body    body    = new Amazon.SimpleEmail.Model.Body()
            {
                Html = new Amazon.SimpleEmail.Model.Content(msg.Body)
            };
            Amazon.SimpleEmail.AmazonSimpleEmailServiceClient client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient(CachedData.SesKey, CachedData.SesSecret, Amazon.RegionEndpoint.USEast1);
            List <string> toAddresses = new List <string>();

            foreach (System.Net.Mail.MailAddress oneToAddr in msg.To)
            {
                toAddresses.Add(oneToAddr.Address);
            }
            Amazon.SimpleEmail.Model.SendEmailRequest req = new Amazon.SimpleEmail.Model.SendEmailRequest();
            req.Destination = new Amazon.SimpleEmail.Model.Destination()
            {
                ToAddresses = toAddresses
            };
            req.Source     = msg.From.DisplayName + " <" + msg.From.Address + ">";
            req.ReturnPath = msg.From.DisplayName + " <" + msg.From.Address + ">";
            req.Message    = new Amazon.SimpleEmail.Model.Message(subject, body);
            client.SendEmailAsync(req).Wait();
        }
        public Interfaces.Models.MessageModel SendMessage
            (Interfaces.Models.MessageModel MessageToSend)
        {
            //get config
            Dictionary <string, string> oMsjConfig = MessageConfig.AgentConfig[MessageToSend.Agent];

            //get destination address
            Amazon.SimpleEmail.Model.Destination oDestination = new Amazon.SimpleEmail.Model.Destination();

            if (MessageToSend.QueueProcessInfo != null &&
                MessageToSend.QueueProcessInfo.Count > 0 &&
                MessageToSend.QueueProcessInfo.Any(qpi => qpi.Item2 == Constants.C_Agent_To))
            {
                oDestination.ToAddresses = MessageToSend.QueueProcessInfo.
                                           Where(qpi => qpi.Item2 == Constants.C_Agent_To).
                                           Select(qpi => qpi.Item3).
                                           Distinct().
                                           ToList();
            }
            else
            {
                throw new Exception("El mensaje no posee destinatarios.");
            }

            //get message info
            Amazon.SimpleEmail.Model.Message oMessage = new Amazon.SimpleEmail.Model.Message();

            //get message body and subject
            string oMsjBody    = oMsjConfig[Constants.C_Agent_AWS_MessageBody];
            string oMsjSubject = oMsjConfig[Constants.C_Agent_AWS_Subject];

            if (MessageToSend.QueueProcessInfo != null && MessageToSend.QueueProcessInfo.Count > 0)
            {
                MessageToSend.QueueProcessInfo.All(MsjParams =>
                {
                    oMsjBody    = oMsjBody.Replace("{" + MsjParams.Item2 + "}", MsjParams.Item3);
                    oMsjSubject = oMsjSubject.Replace("{" + MsjParams.Item2 + "}", MsjParams.Item3);
                    return(true);
                });
            }
            oMessage.Body      = new Amazon.SimpleEmail.Model.Body();
            oMessage.Body.Html = new Amazon.SimpleEmail.Model.Content(oMsjBody);

            //get message subject
            oMessage.Subject = new Amazon.SimpleEmail.Model.Content(oMsjSubject);

            //get email request object
            Amazon.SimpleEmail.Model.SendEmailRequest oEmailRequest = new Amazon.SimpleEmail.Model.SendEmailRequest
                                                                          (oMsjConfig[Constants.C_Agent_AWS_From],
                                                                          oDestination,
                                                                          oMessage);

            //get aws ses client
            Amazon.SimpleEmail.AmazonSimpleEmailServiceClient oClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient
                                                                            (oMsjConfig[Constants.C_Agent_AWS_AccessKeyId],
                                                                            oMsjConfig[Constants.C_Agent_AWS_SecretAccessKey],
                                                                            Amazon.RegionEndpoint.GetBySystemName(oMsjConfig[Constants.C_Agent_AWS_RegionEndpoint]));

            //send email
            oClient.SendEmail(oEmailRequest);

            //set email status ok
            MessageToSend.IsSuccess     = true;
            MessageToSend.ProcessResult = oMsjBody;

            return(MessageToSend);
        }