public void SendEmail() { var client = Amazon.AWSClientFactory.CreateAmazonSimpleEmailServiceClient(EmailProcessingConfigurationManager.Section.Amazon.Key, EmailProcessingConfigurationManager.Section.Amazon.Secret); Destination destination = new Destination(); destination.WithToAddresses("*****@*****.**"); Content subject = new Content(); subject.WithCharset("UTF-8"); subject.WithData("subject"); Content html = new Content(); html.WithCharset("UTF-8"); html.WithData(@"<p>Hi {DonorName},</p> <p>Thank you for making a donation to {CharityName}. In return for your goodwill we have created your very own papal indulgence. You are free to download it, print it and lord your piousness over your friends!</p> <p><a href=""{ServerAuthority}/content/{IndulgenceId}/indulgence.pdf""><img src=""/content/indulgences/{IndulgenceId}/indulgence_25.png"" /></a></p> <p><a href=""{ServerAuthority}/content/{IndulgenceId}/indulgence.pdf"">Click here to download your indulgence</a></p> <p>Regards,</p> <p>Andrew</p> <p>IndulgeMe.cc</p>"); 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); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource("*****@*****.**"); client.SendEmail(request); }
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; }
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; } }
///<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 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!"); }
public override void SendMail(object sender, EmailToSendArgs e) { if (nextCanSend > DateTime.Now) System.Threading.Thread.Sleep(nextCanSend.Subtract(DateTime.Now)); using (var ses = Amazon.AWSClientFactory.CreateAmazonSimpleEmailServiceClient( _configuration.Amazon.Key, _configuration.Amazon.Secret)) { Destination destination = new Destination(); destination.WithToAddresses(e.Message.To.ToStringArray()); Content subject = new Content(); subject.WithCharset("UTF-8"); subject.WithData(e.Message.Subject); Body body = new Body(); if (!string.IsNullOrWhiteSpace(e.Message.Html)) { Content html = new Content(); html.WithCharset("UTF-8"); html.WithData(e.Message.Html); body.WithHtml(html); } if (!string.IsNullOrWhiteSpace(e.Message.Text)) { Content text = new Content(); text.WithCharset("UTF-8"); text.WithData(e.Message.Text); body.WithText(text); } Message message = new Message(); message.WithBody(body); message.WithSubject(subject); SendEmailRequest request = new SendEmailRequest(); request.WithDestination(destination); request.WithMessage(message); request.WithSource(e.Message.From); try { Console.WriteLine("sending email from {0}", e.Message.From); SendEmailResponse response = ses.SendEmail(request); SendEmailResult result = response.SendEmailResult; logger.Debug("Email sent."); logger.Debug(String.Format("Message ID: {0}", result.MessageId)); nextCanSend = _lastSend.AddSeconds(_maxSendRate); } catch (Exception ex) { logger.Fatal("failed to send email", ex); e.SendingFailed = true; } } base.SendMail(sender, e); }