Ejemplo n.º 1
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.myButton);
			
			button.Click += delegate {
				const string ACCESS_KEY = "";
				const string SECRET_KEY = "";
				const string YOUR_EMAIL = "";

				AmazonSimpleEmailServiceClient sesClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1);
				var Name   = FindViewById<EditText>(Resource.Id.name);
				var Rating = FindViewById<RatingBar>(Resource.Id.ratingBar);
				var Comments = FindViewById<EditText>(Resource.Id.comments);

				var messageBody = new Amazon.SimpleEmail.Model.Content (String.Format("Rating: {0}\n\nComments:\n{1}", Rating.Selected, Comments.Text));
				var body = new Amazon.SimpleEmail.Model.Body (messageBody);
				var subject = new Amazon.SimpleEmail.Model.Content (String.Format ("Feedback from {0}", Name.Text));

				var message = new Amazon.SimpleEmail.Model.Message (subject, body);
				var destination = new Amazon.SimpleEmail.Model.Destination (new System.Collections.Generic.List<string> (){ YOUR_EMAIL });

				var sendEmailRequest = new Amazon.SimpleEmail.Model.SendEmailRequest (YOUR_EMAIL, destination, message);

				sesClient.SendEmail (sendEmailRequest);
			};
		}
		void HandleTouchUpInside (object sender, EventArgs e)
		{
			const string ACCESS_KEY = "";
			const string SECRET_KEY = "";
			const string YOUR_EMAIL = "";

			AmazonSimpleEmailServiceClient sesClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1);

			var messageBody = new Amazon.SimpleEmail.Model.Content (String.Format("Rating: {0}\n\nComments:\n{1}", Rating.SelectedSegment, Comments.Text));
			var body = new Amazon.SimpleEmail.Model.Body (messageBody);
			var subject = new Amazon.SimpleEmail.Model.Content (String.Format ("Feedback from {0}", Name.Text));

			var message = new Amazon.SimpleEmail.Model.Message (subject, body);
			var destination = new Amazon.SimpleEmail.Model.Destination (new System.Collections.Generic.List<string> (){ YOUR_EMAIL });

			var sendEmailRequest = new Amazon.SimpleEmail.Model.SendEmailRequest (YOUR_EMAIL, destination, message);

			sesClient.SendEmail (sendEmailRequest);
		}
        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);
        }