Esempio n. 1
0
 /// <summary>
 /// Create a client for the Amazon SimpleEmailService Service with the specified configuration
 /// </summary>
 /// <param name="awsAccessKey">The AWS Access Key associated with the account</param>
 /// <param name="awsSecretAccessKey">The AWS Secret Access Key associated with the account</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc
 /// </param>
 /// <returns>An Amazon SimpleEmailService client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonSimpleEmailService CreateAmazonSimpleEmailServiceClient(
     string awsAccessKey,
     string awsSecretAccessKey, AmazonSimpleEmailServiceConfig config
     )
 {
     return(new AmazonSimpleEmailServiceClient(awsAccessKey, awsSecretAccessKey, config));
 }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonSimpleEmailServiceConfig config = new AmazonSimpleEmailServiceConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(creds, config);

            ListCustomVerificationEmailTemplatesResponse resp = new ListCustomVerificationEmailTemplatesResponse();

            do
            {
                ListCustomVerificationEmailTemplatesRequest req = new ListCustomVerificationEmailTemplatesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListCustomVerificationEmailTemplates(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.CustomVerificationEmailTemplates)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Esempio n. 3
0
        public static IAmazonSimpleEmailService CreateClient()
        {
            var credentials = new BasicAWSCredentials("__ACCESS_KEY__", "__SECRET_KEY__");

            var config = new AmazonSimpleEmailServiceConfig {
                ServiceURL = "http://localhost:4566"
            };

            return(new AmazonSimpleEmailServiceClient(credentials, config));
        }
Esempio n. 4
0
        private AmazonSimpleEmailServiceClient InitializeClient()
        {
            AmazonSimpleEmailServiceConfig config = new AmazonSimpleEmailServiceConfig();

            config.RegionEndpoint = RegionEndpoint.USEast1;

            // config.ServiceURL = ConfigurationManager.AppSettings["SESServiceUrl"];

            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(config);

            return(client);
        }
Esempio n. 5
0
        public Task SendRawEmail(string htmlBody, string subject, string[] to, string from, bool isHtmlBody, string attachedFileName, string fileContent)
        {
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, Encoding.UTF8, "text/html");

            MailMessage mailMessage = new MailMessage();

            mailMessage.From = new MailAddress(from);
            mailMessage.To.Add(new MailAddress(to.FirstOrDefault()));

            mailMessage.Subject         = subject;
            mailMessage.SubjectEncoding = Encoding.UTF8;

            if (htmlBody != null)
            {
                mailMessage.AlternateViews.Add(htmlView);
            }

            if (attachedFileName.Trim() != "")
            {
                string folderName = "Attachment";
                string attachPath = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"), folderName);
                attachPath = (Path.Combine(attachPath, attachedFileName));

                if (System.IO.File.Exists(attachPath))
                {
                    try
                    {
                        System.Net.Mail.Attachment objAttach = new System.Net.Mail.Attachment(attachPath);
                        objAttach.ContentType = new ContentType(fileContent);
                        System.Net.Mime.ContentDisposition disposition = objAttach.ContentDisposition;
                        disposition.DispositionType  = "attachment";
                        disposition.CreationDate     = System.IO.File.GetCreationTime(attachPath);
                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachPath);
                        disposition.ReadDate         = System.IO.File.GetLastAccessTime(attachPath);
                        mailMessage.Attachments.Add(objAttach);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            RawMessage          rawMessage = new RawMessage(ConvertMailMessageToMemoryStream(mailMessage));
            SendRawEmailRequest request    = new SendRawEmailRequest(rawMessage);

            Amazon.RegionEndpoint          regionEndPoint = Amazon.RegionEndpoint.USWest2;
            AmazonSimpleEmailServiceConfig config         = new AmazonSimpleEmailServiceConfig();

            config.RegionEndpoint = regionEndPoint;
            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_mailSettings.AwsAccessKeyId, _mailSettings.AwsSecretAccessKey, config);

            return(client.SendRawEmailAsync(request));
        }
Esempio n. 6
0
        protected IAmazonSimpleEmailService CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonSimpleEmailServiceConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonSimpleEmailServiceClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
Esempio n. 7
0
        public Task ExecuteAsync(SendEmailRequest request)
        {
            try
            {
                Amazon.RegionEndpoint          regionEndPoint = Amazon.RegionEndpoint.USWest2;
                AmazonSimpleEmailServiceConfig config         = new AmazonSimpleEmailServiceConfig();
                config.RegionEndpoint = regionEndPoint;
                AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_mailSettings.AwsAccessKeyId, _mailSettings.AwsSecretAccessKey, config);
                return(client.SendEmailAsync(request));
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Esempio n. 8
0
        public static string ProcessRequest(AbsenceModel absenceModel)
        {
            try
            {
                const String from = "*****@*****.**";
                // Construct an object to contain the recipient address.
                Destination destination = new Destination();
                destination.ToAddresses = (new List <string>()
                {
                    ""
                });
                Content emailSubject = new Content("asdasd");
                Content textBody     = new Content("asdsad");
                Body    body         = new Body();
                body.Html = textBody;
                // Create a message with the specified subject and body.
                Amazon.SimpleEmail.Model.Message message      = new Amazon.SimpleEmail.Model.Message(emailSubject, body);
                SendEmailRequest               request        = new SendEmailRequest(from, destination, message);
                Amazon.RegionEndpoint          regionEndPoint = Amazon.RegionEndpoint.USWest2;
                AmazonSimpleEmailServiceConfig config         = new AmazonSimpleEmailServiceConfig();
                config.RegionEndpoint = regionEndPoint;
                var key = "AKIAISEURJBJ3YL4J6EA";
                var sec = "7iiVlPs51EEoZw5+TjlE+z/XdEy9WCa0rvF91u6O";
                // Instantiate an Amazon SES client, which will make the service call.
                AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(key, sec, config);
                client.SendEmailAsync(request);
            }

            catch (Exception ex)
            {
                //log into database.

                string exception = "Email Sending Failed Amazon SES";
                if (ex.StackTrace != null)
                {
                    exception = exception + "Main Stack Trace: " + ex.StackTrace;
                    exception = exception + " Main Message " + Convert.ToString(ex.Message);
                }
                if (ex.InnerException != null)
                {
                    exception = exception + "Inner Stack Trace: " + ex.StackTrace;
                    exception = exception + " Inner Message " + Convert.ToString(ex.Message);
                }
            }
            return("");
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonSimpleEmailServiceConfig config = new AmazonSimpleEmailServiceConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(creds, config);

            ListVerifiedEmailAddressesResponse resp = new ListVerifiedEmailAddressesResponse();
            ListVerifiedEmailAddressesRequest  req  = new ListVerifiedEmailAddressesRequest
            {
            };

            resp = client.ListVerifiedEmailAddresses(req);
            CheckError(resp.HttpStatusCode, "200");

            foreach (var obj in resp.VerifiedEmailAddresses)
            {
                AddObject(obj);
            }
        }
Esempio n. 10
0
        // <returns></returns>
        public static bool sendEmailAttachment(string email, string subject, string body)
        {
            var awsConfig = new AmazonSimpleEmailServiceConfig();

            awsConfig.RegionEndpoint = Amazon.RegionEndpoint.USWest2;

            var awsClient = new AmazonSimpleEmailServiceClient("AKIAJENNMZYOVK4V7XJA", "AnNyJMBTBAGvhcUF1N6gVfW1vQtmyC4allr1NVCf", awsConfig);

            Destination dest = new Destination();

            dest.ToAddresses.Add(email);
            //Attachment att = new Attachment();
            // string subject = "Supreme Brands App details";

            Body bd = new Body();

            bd.Html = new Amazon.SimpleEmail.Model.Content(body);


            Amazon.SimpleEmail.Model.Content title = new Amazon.SimpleEmail.Model.Content(subject);

            Message message = new Message(title, bd);

            try
            {
                SendEmailRequest ser = new SendEmailRequest("*****@*****.**", dest, message);

                SendEmailResponse seResponse = awsClient.SendEmail(ser);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Create a client for the Amazon SimpleEmailService Service with AWSCredentials and an AmazonSimpleEmailService Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon SimpleEmailService client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonSimpleEmailService CreateAmazonSimpleEmailServiceClient(AWSCredentials credentials, AmazonSimpleEmailServiceConfig config)
 {
     return(new AmazonSimpleEmailServiceClient(credentials, config));
 }
Esempio n. 12
0
        public static bool sendVerificationEmailAmazonSES(string email)
        {
            string accesKey  = ConfigurationManager.AppSettings["AWSAccessKey"].ToString();
            string secretKey = ConfigurationManager.AppSettings["AWSSecretKey"].ToString();
            String HOST      = "https://" + ConfigurationManager.AppSettings["AWSServer"].ToString();
            var    region    = RegionEndpoint.USWest2;
            AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig {
                ServiceURL = HOST, RegionEndpoint = region
            };

            bool result = false;

            //try {

            //.GetBySystemName("us-west-2");
            Amazon.SimpleEmail.Model.VerifyEmailAddressRequest  request  = new Amazon.SimpleEmail.Model.VerifyEmailAddressRequest();
            Amazon.SimpleEmail.Model.VerifyEmailAddressResponse response = new Amazon.SimpleEmail.Model.VerifyEmailAddressResponse();
            Amazon.SimpleEmail.AmazonSimpleEmailServiceClient   client   = new AmazonSimpleEmailServiceClient(accesKey, secretKey, region);
            //, amConfig);

            if (client != null)
            {
                request.EmailAddress = email.Trim();
                response             = client.VerifyEmailAddress(request);

                if (!string.IsNullOrEmpty(response.ResponseMetadata.RequestId))
                {
                    result = true;
                }
            }
            //}
            //catch (Exception ex)
            // {
            //     Console.WriteLine(ex.Message);
            //   }

            return(result);

            //  //INITIALIZE AWS CLIENT//
            // // AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig();
            // // amConfig.UseSecureStringForAwsSecretKey  = false;
            ////  amConfig.c
            //  //String HOST = "http://"+ConfigurationManager.AppSettings["AWSServer"].ToString();
            //  try
            //  {
            //      //AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig { ServiceURL = HOST };

            //      string HOST = ConfigurationManager.AppSettings["AWSServer"].ToString();
            //      const int PORT = 587;
            //      // Create an SMTP client with the specified host name and port.
            //      using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(accesKey, secretKey))
            //      {
            //          // Create a network credential with your SMTP user name and password.
            //          client.Credentials = new System.Net.NetworkCredential(accesKey, secretKey);

            //          // Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
            //          // the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
            //          //client.EnableSsl = true;

            //          //AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient(accesKey, secretKey);
            //          //ConfigurationManager.AppSettings["AWSAccessKey"].ToString(),
            //          //ConfigurationManager.AppSettings["AWSSecretKey"].ToString(), amConfig);

            //          //VERIFY EMAIL//
            //          VerifyEmailAddressRequest veaRequest = new VerifyEmailAddressRequest();
            //          veaRequest.EmailAddress = email;// "Your_Email_To_Verify";
            //          VerifyEmailAddressResponse veaResponse = client.VerifyEmailAddress(veaRequest);
            //      }
            //      // int x = 0;
            //  }
            //  catch (Exception ex)
            //  {
            //      Console.WriteLine(ex.Message);

            //      //return false;
            //  }
            //Response.Write(veaResponse..ResponseMetadata.RequestId);
        }