public bool SendEmail(String From, String To, String Subject, String Text, String HTML, String emailReplyTo, String returnPath) { if (Text != null && HTML != null) { String from = From; List<String> to = To.Replace(", ", ",").Split(',').ToList(); Destination destination = new Destination(); destination.WithToAddresses(to); //destination.WithCcAddresses(cc); //destination.WithBccAddresses(bcc); Amazon.SimpleEmail.Model.Content subject = new Amazon.SimpleEmail.Model.Content(); subject.WithCharset("UTF-8"); subject.WithData(Subject); Amazon.SimpleEmail.Model.Content html = new Amazon.SimpleEmail.Model.Content(); html.WithCharset("UTF-8"); html.WithData(HTML); Amazon.SimpleEmail.Model.Content text = new Amazon.SimpleEmail.Model.Content(); text.WithCharset("UTF-8"); text.WithData(Text); Body body = new Body(); body.WithHtml(html); body.WithText(text); Message message = new Message(); message.WithBody(body); message.WithSubject(subject); //AmazonSimpleEmailServiceConfig config = new AmazonSimpleEmailServiceConfig(); //config.ServiceURL = "http://aws.amazon.com/articles/3051?_encoding=UTF8&jiveRedirect=1"; //config.ProxyPort = 465; // AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(awsAccessKeyId, awsSecretAccessKey); AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AppConfig["AWSAccessKey"], AppConfig["AWSSecretKey"]); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource(from); if (emailReplyTo != null) { List<String> replyto = emailReplyTo.Replace(", ", ",").Split(',').ToList(); request.WithReplyToAddresses(replyto); } if (returnPath != null) { request.WithReturnPath(returnPath); } try { SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; Console.WriteLine("Email sent."); Console.WriteLine(String.Format("Message ID: {0}",result.MessageId)); return true; } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } } Console.WriteLine("Specify Text and/or HTML for the email body!"); return false; }
public static Boolean SendEmail(String From, String To, String Subject, String Text = null, String HTML = null, String emailReplyTo = null, String returnPath = null) { if (Text != null || HTML != null) { try { String from = From; List<String> to = To .Replace(", ", ",") .Split(',') .ToList(); Destination destination = new Destination(); destination.WithToAddresses(to); //destination.WithCcAddresses(cc); //destination.WithBccAddresses(bcc); Content subject = new Content(); subject.WithCharset("UTF-8"); subject.WithData(Subject); Body body = new Body(); if (HTML != null) { Content html = new Content(); html.WithCharset("UTF-8"); html.WithData(HTML); body.WithHtml(html); } if (Text != null) { Content text = new Content(); text.WithCharset("UTF-8"); text.WithData(Text); body.WithText(text); } Message message = new Message(); message.WithBody(body); message.WithSubject(subject); string awsAccessKey = AWSAccessKey; string awsSecretKey = AWSSecretKey; //AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AppConfig["AWSAccessKey"], AppConfig["AWSSecretKey"]); AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(awsAccessKey, awsSecretKey); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource(from); if (emailReplyTo != null) { List<String> replyto = emailReplyTo .Replace(", ", ",") .Split(',') .ToList(); request.WithReplyToAddresses(replyto); } if (returnPath != null) { request.WithReturnPath(returnPath); } SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; Console.WriteLine("Email sent."); Console.WriteLine(String.Format("Message ID: {0}", result.MessageId)); return true; } catch (Exception ex) { Console.WriteLine(ex.Message); //throw; return false; } finally { String queueMessage = String.Format("From: {1}{0}To: {2}{0}Subject: {3}{0}Message:{0}{4}", Environment.NewLine, From, To, Subject, Text ?? HTML); QueueSupport.CurrStatisticsQueue.AddMessage(new CloudQueueMessage(queueMessage)); } } Console.WriteLine("Specify Text and/or HTML for the email body!"); return false; }
///<Summary> /// Gets the answer ///</Summary> public static Boolean SendEmail(String From, String To, String Subject, String Text = null, String HTML = null, String emailReplyTo = null, String returnPath = null) { if (Text != null && HTML != null) { String from = From; List<String> to = To .Replace(", ", ",") .Split(',') .ToList(); Destination destination = new Destination(); destination.WithToAddresses(to); //destination.WithCcAddresses(cc); //destination.WithBccAddresses(bcc); Amazon.SimpleEmail.Model.Content subject = new Amazon.SimpleEmail.Model.Content(); subject.WithCharset("UTF-8"); subject.WithData(Subject); Amazon.SimpleEmail.Model.Content html = new Amazon.SimpleEmail.Model.Content(); html.WithCharset("UTF-8"); html.WithData(HTML); Amazon.SimpleEmail.Model.Content text = new Amazon.SimpleEmail.Model.Content(); text.WithCharset("UTF-8"); text.WithData(Text); Body body = new Body(); body.WithHtml(html); body.WithText(text); Amazon.SimpleEmail.Model.Message message = new Amazon.SimpleEmail.Model.Message(); message.WithBody(body); message.WithSubject(subject); AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AppConfig["AWSAccessKey"], AppConfig["AWSSecretKey"]); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource(from); if (emailReplyTo != null) { List<String> replyto = emailReplyTo .Replace(", ", ",") .Split(',') .ToList(); request.WithReplyToAddresses(replyto); } if (returnPath != null) { request.WithReturnPath(returnPath); } try { SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; return true; } catch { return false; } } return false; }
public string SendEmail(Hashtable State, string from, string to, string cc, string bcc, string subject, string body, string attach_path, bool isBodyHtml) { string AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"]; string AWSSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"]; AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AWSAccessKey, AWSSecretKey); SendEmailRequest request = new SendEmailRequest(); Destination destination = new Destination(); List<String> To = new List<String>(to.Replace(", ", ",").Split(',')); destination.WithToAddresses(To); if (cc != null && cc.Length > 0) { List<String> CC = new List<String>(cc.Replace(", ", ",").Split(',')); destination.WithCcAddresses(CC); } if (bcc != null && bcc.Length > 0) { List<String> BCC = new List<String>(bcc.Replace(", ", ",").Split(',')); destination.WithBccAddresses(BCC); } request.WithDestination(destination); Content SESsubject = new Content(); SESsubject.WithCharset("UTF-8"); SESsubject.WithData(subject); Body SESbody = new Body(); if (isBodyHtml) { Content SEShtml = new Content(); SEShtml.WithCharset("UTF-8"); SEShtml.WithData(body); SESbody.WithHtml(SEShtml); } else { Content text = new Content(); text.WithCharset("UTF-8"); text.WithData(body); SESbody.WithText(text); } Message message = new Message(); message.WithBody(SESbody); message.WithSubject(SESsubject); request.WithMessage(message); request.WithSource(from); List<String> replyto = new List<String>(from.Replace(", ", ",").Split(',')); request.WithReplyToAddresses(replyto); /* if (returnPath != null) { request.WithReturnPath(returnPath); }*/ try { SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; return "OK"; } catch (Exception ex) { Util util = new Util(); util.LogError(State, ex); return ex.Message; } }
public static Boolean SendEmail(String From, Recipient recipient, String Subject, String Text = null, String HTML = null, String emailReplyTo = null, String returnPath = null) { if (Text != null && HTML != null) { String from = From; List<String> to = recipient.Email .Replace(", ", ",") .Split(',') .ToList(); Destination destination = new Destination(); destination.WithToAddresses(recipient.Email); //destination.WithCcAddresses(cc); //destination.WithBccAddresses(bcc); Content subject = new Content(); subject.WithCharset("UTF-8"); subject.WithData(Subject); Content html = new Content(); html.WithCharset("UTF-8"); html.WithData(HTML); Content text = new Content(); text.WithCharset("UTF-8"); text.WithData(Text); Body body = new Body(); body.WithHtml(html); body.WithText(text); Message message = new Message(); message.WithBody(body); message.WithSubject(subject); string accessKey = ConfigurationManager.AppSettings["AWSAccessKey"]; string secretKey = ConfigurationManager.AppSettings["AWSSecretKey"]; AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(accessKey, secretKey); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource(from); if (emailReplyTo != null) { List<String> replyto = emailReplyTo .Replace(", ", ",") .Split(',') .ToList(); request.WithReplyToAddresses(replyto); } if (returnPath != null) { request.WithReturnPath(returnPath); } try { SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; return true; } catch (Exception ex) { recipient.ErrorMessage = ex.Message; return false; } } throw new Exception("Specify Text and/or HTML for the email body!"); }