public static bool SendEmailWithAmazone(string FROM, string TO, string SUBJECT, string BODY, string AWSAccessKey, string AWSSecrectKey, string NameSender) { string Name = NameSender; Destination destination = new Destination().WithToAddresses(new List<string>() { TO }); // Create the subject and body of the message. Amazon.SimpleEmail.Model.Content subject = new Amazon.SimpleEmail.Model.Content().WithData(SUBJECT); Amazon.SimpleEmail.Model.Content textBody = new Amazon.SimpleEmail.Model.Content().WithData(BODY); Body body = new Body().WithHtml(textBody); // Create a message with the specified subject and body. Message message = new Message().WithSubject(subject).WithBody(body); string Fr = String.Format("{0}<{1}>", Name, FROM); SendEmailRequest request = new SendEmailRequest().WithSource(Fr).WithDestination(destination).WithMessage(message); using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(AWSAccessKey, AWSSecrectKey)) { // Send the email. try { client.SendEmail(request); return true; } catch (Exception) { return false; } } }
public static void SESSendEmail() { #region SESSendEmail var sesClient = new AmazonSimpleEmailServiceClient(); var dest = new Destination { ToAddresses = new List<string>() { "*****@*****.**" }, CcAddresses = new List<string>() { "*****@*****.**" } }; var from = "*****@*****.**"; var subject = new Content("You're invited to the meeting"); var body = new Body(new Content("Please join us Monday at 7:00 PM.")); var msg = new Message(subject, body); var request = new SendEmailRequest { Destination = dest, Message = msg, Source = from }; sesClient.SendEmail(request); #endregion }
public void SendEmails(AmazonSimpleEmailServiceClient aClient) { IEnumerable<EmailJob> myEmailsToSendOut = theEmailRepo.GetEmailJobsToBeSent(); if (myEmailsToSendOut.Count<EmailJob>() != 0) { ConsoleMessageWithDate("Have to send emails: " + myEmailsToSendOut.Count<EmailJob>()); foreach (EmailJob myEmailJob in myEmailsToSendOut) { SendEmailRequest myRequest = new SendEmailRequest(); List<string> mySendTo = new List<string>(); mySendTo.Add(myEmailJob.ToEmail); Content mySubject = new Content(myEmailJob.Subject); Body myBody = new Body(); myBody.Html = new Content(myEmailJob.Body); myRequest.Destination = new Destination(mySendTo); myRequest.Message = new Message(mySubject, myBody); myRequest.Source = myEmailJob.FromEmail; //Change flag with the send in between so we can track if shit happened theEmailRepo.MarkEmailPresentToTrue(myEmailJob.Id); aClient.SendEmail(myRequest); theEmailRepo.MarkEmailPostsentToTrue(myEmailJob.Id); ConsoleMessageWithDate("A " + myEmailJob.EmailDescription + " has been sent to " + myEmailJob.ToEmail + " from " + myEmailJob.FromEmail); } } else { ConsoleMessageWithDate("No emails required to be sent out"); } }
public void Send(string name, string replyTo, string messageBody) { var destination = new Destination() { ToAddresses = new List<string>() { TO } }; var subject = new Content(SUBJECT); var body = new Body() { Html = new Content(string.Format(BODY, name, messageBody)) }; var message = new Message(subject, body); var request = new SendEmailRequest(FROM, destination, message); request.ReplyToAddresses = new List<string> { replyTo }; var region = Amazon.RegionEndpoint.USEast1; using (var client = new AmazonSimpleEmailServiceClient(region)) { try { client.SendEmail(request); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } }
public Task<bool> SendEmail(string to, string subject, string htmlBody) { if (string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(htmlBody) || !to.IsEmail()) return Task.FromResult(false); var destination = new Destination { ToAddresses = new List<string> { to } }; var contentSubject = new Content { Charset = Encoding.UTF8.EncodingName, Data = subject }; var contentBody = new Content { Charset = Encoding.UTF8.EncodingName, Data = htmlBody }; var body = new Body { Html = contentBody }; var message = new Message { Body = body, Subject = contentSubject }; var request = new SendEmailRequest { Source = FROM_EMAIL, Destination = destination, Message = message }; var client = new AmazonSimpleEmailServiceClient(); try { client.SendEmail(request); } catch (Exception ex) { return Task.FromResult(false); } return Task.FromResult(true); }
protected void Page_Load(object sender, EventArgs e) { AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig(); amConfig.UseSecureStringForAwsSecretKey = false; AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient(ConfigurationManager.AppSettings["AWSAccessKey"].ToString(), ConfigurationManager.AppSettings["AWSSecretKey"].ToString(),amConfig); ArrayList to = new ArrayList(); //ADD AS TO 50 emails per one sending method////////////////////// //to.Add("*****@*****.**"); //to.Add("*****@*****.**"); to.Add("*****@*****.**"); to.Add("*****@*****.**"); to.Add("*****@*****.**"); to.Add("*****@*****.**"); to.Add("*****@*****.**"); to.Add("*****@*****.**"); Destination dest = new Destination(); dest.WithToAddresses((string[])to.ToArray(typeof(string))); //dest.WithToAddresses((string[])to.ToArray(typeof(string))); string body = "INSERT HTML BODY HERE"; string subject = "INSERT EMAIL SUBJECT HERE"; Body bdy = new Body(); bdy.Html = new Amazon.SimpleEmail.Model.Content(body); Amazon.SimpleEmail.Model.Content title = new Amazon.SimpleEmail.Model.Content(subject); Message message = new Message(title, bdy); //VerifyEmailAddressRequest veaRequest = new VerifyEmailAddressRequest(); // veaRequest.EmailAddress = "*****@*****.**"; // VerifyEmailAddressResponse veaResponse = amzClient.VerifyEmailAddress(veaRequest); SendEmailRequest ser = new SendEmailRequest("*****@*****.**", dest, message); ser.WithReturnPath("*****@*****.**"); SendEmailResponse seResponse = amzClient.SendEmail(ser); SendEmailResult seResult = seResponse.SendEmailResult; //GetSendStatisticsRequest request=new GetSendStatisticsRequest(); //GetSendStatisticsResponse obj = amzClient.GetSendStatistics(request); //List<SendDataPoint> sdata = new List<SendDataPoint>(); //sdata=obj.GetSendStatisticsResult.SendDataPoints; //Int64 sentCount = 0,BounceCount=0,DeleveryAttempts=0; //for (int i = 0; i < sdata.Count; i++) //{ // BounceCount = BounceCount +sdata[i].Bounces; // DeleveryAttempts = DeleveryAttempts + sdata[i].DeliveryAttempts; //} //sentCount = DeleveryAttempts - BounceCount; }
public void SendEmail(string to, string subject, string bodyText, string bodyHtml) { using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.EUWest1)) { var content = new Content(subject); var body = new Body{Html = new Content(bodyHtml), Text = new Content(bodyText)}; var message = new Message(content, body); var destination = new Destination(new List<string> {to}); var sendEmailRequest = new SendEmailRequest(FromEmail, destination, message); client.SendEmail(sendEmailRequest); } }
public void Send(string from, IEnumerable<string> to, IEnumerable<string> bcc, string subject, string body) { var bodyContent = new Content(body) { Charset = "UTF-8" }; var message = new Message(new Content(subject), new Body { Html = bodyContent }); var destinations = new List<Destination>(); var destination = new Destination(); if (to != null) { foreach (var email in to) { if(string.IsNullOrEmpty(email)) throw new ArgumentException("To Email can not be null or empty"); destination.ToAddresses.Add(email); if (destination.ToAddresses.Count != _sender.MaxRecipientPerBatch) continue; destinations.Add(destination); destination = new Destination(); } } if (bcc != null) { foreach (var email in bcc) { if (string.IsNullOrEmpty(email)) throw new ArgumentException("Bbc Email can not be null or empty"); destination.BccAddresses.Add(email); if (destination.ToAddresses.Count + destination.BccAddresses.Count != _sender.MaxRecipientPerBatch) continue; destinations.Add(destination); destination = new Destination(); } } if (destination.ToAddresses.Count + destination.BccAddresses.Count != 0) destinations.Add(destination); foreach (var d in destinations) _sender.Send(new SendEmailRequest(from, d, message)); }
/// <summary> /// Sends an email with opt out option /// </summary> /// <param name="fromEmail"></param> /// <param name="toEmail"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <returns></returns> public bool SendMail(string fromEmail, string toEmail, string subject, string body) { if (string.IsNullOrEmpty(toEmail) || string.IsNullOrEmpty(fromEmail) || string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(body)) return false; try { toEmail = toEmail.Trim(); fromEmail = fromEmail.Trim(); var amzClient = new AmazonSimpleEmailServiceClient( AmazonCloudConfigs.AmazonAccessKey, AmazonCloudConfigs.AmazonSecretKey, RegionEndpoint.USEast1); var dest = new Destination(); dest.ToAddresses.Add(toEmail); body = body + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + "----------------------------" + Environment.NewLine + "Unsubscribe From Email: " + // TODO: LOCALIZE Environment.NewLine + GeneralConfigs.EmailSettingsURL + Environment.NewLine; var bdy = new Body {Text = new Content(body)}; var title = new Content(subject); var message = new Message(title, bdy); fromEmail = string.Format("{0} <{1}>", GeneralConfigs.SiteName, fromEmail); var ser = new SendEmailRequest(fromEmail, dest, message); var response = amzClient.SendEmail(ser); return true; } catch (Exception ex) { return false; } }
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) { } }
public Task<string> Send(IEnumerable<string> to, IEnumerable<string> cc, string from, string title, string htmlBody, string textBody) { AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_accessKey, _secretKey); Destination destination = new Destination(); destination.ToAddresses = to.ToList(); Content subject = new Content(title); Body bodyContent = new Body() { Html = htmlBody == null ? null : new Content(htmlBody), Text = textBody == null ? null : new Content(textBody) }; Message message = new Message(subject, bodyContent); SendEmailRequest request = new SendEmailRequest { ReplyToAddresses = new List<string>() {@from}, Destination = destination, Message = message }; SendEmailResponse response = client.SendEmail(request); return Task.FromResult(response.MessageId); }
public static void SendEmailRegisterInterest(string emailContentPath, string email) { var recipientEmail = SetRecipientEmail(email); // Send email after adding user to interested people var bodyContent = new Content(System.IO.File.ReadAllText(emailContentPath)); // create email request var request = new SendEmailRequest() .WithDestination(new Destination(new List<string> { recipientEmail })) .WithSource("*****@*****.**") .WithReturnPath("*****@*****.**") .WithMessage(new Message() .WithSubject(new Content("Thanks for joining the GreenMoney waiting list")) .WithBody(new Body().WithHtml(bodyContent)) ); // send it var client = new AmazonSimpleEmailServiceClient("AKIAIDP5FFSCJUHHC4QA", "NKAzwbtwwhvKuQZj2t6OXxOhaOEuaBYh3E34Jxbs"); client.SendEmail(request); }
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 static bool SendEmailWithAmazone(string FROM, string TO, string SUBJECT, string BODY, string AWSAccessKey, string AWSSecrectKey, string NameSender) { log4net.ILog log = log4net.LogManager.GetLogger("ErrorRollingLogFileAppender"); try { string Name = NameSender; Destination destination = new Destination().WithToAddresses(new List<string>() { TO }); // Create the subject and body of the message. Amazon.SimpleEmail.Model.Content subject = new Amazon.SimpleEmail.Model.Content().WithData(SUBJECT); Amazon.SimpleEmail.Model.Content textBody = new Amazon.SimpleEmail.Model.Content().WithData(BODY); Body body = new Body().WithHtml(textBody); // Create a message with the specified subject and body. Message message = new Message().WithSubject(subject).WithBody(body); string Fr = String.Format("{0}<{1}>", Name, FROM); SendEmailRequest request = new SendEmailRequest().WithSource(Fr).WithDestination(destination).WithMessage(message); using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(AWSAccessKey, AWSSecrectKey)) { // Send the email. try { client.SendEmail(request); return true; } catch (Exception e) { log.Error("ProcessSendEmail-callSendBulkMail_BySubGroup" + e); return false; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); log.Error("ProcessSendEmail-callSendBulkMail_BySubGroup" + ex);return false; } }
private Message BuildMessage(Indulgence indulgence) { var templateDoc = XDocument.Load(HostingEnvironment.MapPath("~/content/emailTemplates/indulgenceEmail.xml")); string subjectText = templateDoc.Element("email").Element("subject").Value; string textBody = templateDoc.Element("email").Element("body").Element("text").Value; string htmlBody = templateDoc.Element("email").Element("body").Element("html").Value; subjectText = subjectText .Replace("@DonorName", indulgence.Name) .Replace("@CharityName", indulgence.CharityName); textBody = textBody .Replace("@DonorName", indulgence.Name) .Replace("@CharityName", indulgence.CharityName); htmlBody = htmlBody .Replace("@DonorName", indulgence.Name) .Replace("@CharityName", indulgence.CharityName); Content subject = new Content(); subject.Charset = "utf-8"; subject.Data = subjectText; Content html = new Content(); html.Charset="UTF-8"; html.Data= htmlBody; Content text = new Content(); text.Charset="UTF-8"; text.Data=textBody; Body body = new Body(); body.Html=html; body.Text=text; Message message = new Message(); message.Body=body; message.Subject=subject; return message; }
protected void Page_Load(object sender, EventArgs e) { AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig(); amConfig.UseSecureStringForAwsSecretKey = false; AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient(ConfigurationManager.AppSettings["AWSAccessKey"].ToString(), ConfigurationManager.AppSettings["AWSSecretKey"].ToString(), amConfig); ArrayList to = new ArrayList(); to.Add("*****@*****.**"); //to.Add("*****@*****.**"); for (int i = 0; i < to.Count; i++) { Destination dest = new Destination(); dest.WithToAddresses(to[i].ToString()); string body = "Hello this is testing AWS"; string subject = "Test AWS"; Body bdy = new Body(); bdy.Html = new Amazon.SimpleEmail.Model.Content(body); Amazon.SimpleEmail.Model.Content title = new Amazon.SimpleEmail.Model.Content(subject); Message message = new Message(title, bdy); SendEmailRequest ser = new SendEmailRequest("*****@*****.**", dest, message); ser.WithReturnPath("*****@*****.**"); SendEmailResponse seResponse = amzClient.SendEmail(ser); SendEmailResult seResult = seResponse.SendEmailResult; } //GetSendStatisticsRequest request = new GetSendStatisticsRequest(); //GetSendStatisticsResponse obj = amzClient.GetSendStatistics(request); //List<SendDataPoint> sdata = new List<SendDataPoint>(); //sdata = obj.GetSendStatisticsResult.SendDataPoints; //Int64 sentCount = 0, BounceCount = 0, DeleveryAttempts = 0; //for (int i = 0; i < sdata.Count; i++) //{ // BounceCount = BounceCount + sdata[i].Bounces; // DeleveryAttempts = DeleveryAttempts + sdata[i].DeliveryAttempts; //} //sentCount = DeleveryAttempts - BounceCount; }
public bool SendEmail() { //INITIALIZE AWS CLIENT// AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig(); //amConfig.UseSecureStringForAwsSecretKey = false; AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient( AppSettingHelper.GetAmazonAccessKey(),AppSettingHelper.GetAmazonSecretKey(),//ConfigurationManager.AppSettings["AWSAccessKey"].ToString(), RegionEndpoint.USEast1);// ConfigurationManager.AppSettings["AWSSecretKey"].ToString(), amConfig); //ArrayList that holds To Emails. It can hold 1 Email to any //number of emails in case what to send same message to many users. var to = new List<string>(); to.Add("*****@*****.**"); //Create Your Bcc Addresses as well as Message Body and Subject Destination dest = new Destination(); dest.BccAddresses.Add("*****@*****.**"); //string body = Body; string subject = "Subject : " + "Demo Mail"; Body bdy = new Body(); bdy.Html = new Amazon.SimpleEmail.Model.Content("Test Mail"); Amazon.SimpleEmail.Model.Content title = new Amazon.SimpleEmail.Model.Content(subject); Message message = new Message(title, bdy); //Create A Request to send Email to this ArrayList with this body and subject try { SendEmailRequest ser = new SendEmailRequest("*****@*****.**", dest, message); SendEmailResponse seResponse = amzClient.SendEmail(ser); // SendEmailResult seResult = seResponse.SendEmailResult; } catch (Exception ex) { } return true; }
/// <summary> /// Constructs a new Message object. /// Callers should use the properties initialize any additional object members. /// </summary> /// /// <param name="subject"> The subject of the message: A short summary of the content, which will appear in the recipient's inbox. </param> /// <param name="body"> The message body. </param> public Message(Content subject, Body body) { this.subject = subject; this.body = body; }
/// <summary> /// Instantiates Message with the parameterized properties /// </summary> /// <param name="subject">The subject of the message: A short summary of the content, which will appear in the recipient's inbox.</param> /// <param name="body">The message body.</param> public Message(Content subject, Body body) { _subject = subject; _body = body; }
/// <summary> /// Instantiates Body with the parameterized properties /// </summary> /// <param name="text">The content of the message, in text format. Use this for text-based email clients, or clients on high-latency networks (such as mobile devices). </param> public Body(Content text) { _text = text; }
/// <summary> /// Sets the Html property /// </summary> /// <param name="html">The value to set for the Html property </param> /// <returns>this instance</returns> public Body WithHtml(Content html) { this.html = html; return this; }
private NoticeSendResult SendMessage(NotifyMessage m) { //Check if we need to query stats RefreshQuotaIfNeeded(); if (quota != null) { lock (locker) { if (quota.Max24HourSend <= quota.SentLast24Hours) { //Quota exceeded, queue next refresh to +24 hours lastRefresh = DateTime.UtcNow.AddHours(24); log.WarnFormat("Quota limit reached. setting next check to: {0}", lastRefresh); return NoticeSendResult.SendingImpossible; } } } var dest = new Destination { ToAddresses = m.To.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(a => MailAddressUtils.Create(a).Address).ToList(), }; var subject = new Content(MimeHeaderUtils.EncodeMime(m.Subject)) { Charset = Encoding.UTF8.WebName, }; Body body; if (m.ContentType == Pattern.HTMLContentType) { body = new Body(new Content(HtmlUtil.GetText(m.Content)) { Charset = Encoding.UTF8.WebName }); body.Html = new Content(GetHtmlView(m.Content)) { Charset = Encoding.UTF8.WebName }; } else { body = new Body(new Content(m.Content) { Charset = Encoding.UTF8.WebName }); } var from = MailAddressUtils.Create(m.From).ToEncodedString(); var request = new SendEmailRequest(from, dest, new Message(subject, body)); if (!string.IsNullOrEmpty(m.ReplyTo)) { request.ReplyToAddresses.Add(MailAddressUtils.Create(m.ReplyTo).Address); } ThrottleIfNeeded(); var response = ses.SendEmail(request); lastSend = DateTime.UtcNow; return response != null ? NoticeSendResult.OK : NoticeSendResult.TryOnceAgain; }
//Send notification to user via email. /// <summary> /// Uses SES to send an email to a user. /// </summary> /// <param name="email">The email.</param> private void SendEmail(String email) { try { String[] arrayTO = new String[1]; arrayTO[0] = email; List<string> listTO = arrayTO.ToList<String>(); // Construct an object to contain the recipient address. Destination destination = new Destination().WithToAddresses(listTO); String FROM = "*****@*****.**"; String SUBJECT = "Welcome to Cookbook!"; String BODY = "Welcome to Cookbook! Thank you so much for joining us. We hope that you will enjoy using our website."; // Create the subject and body of the message. Content subject = new Content().WithData(SUBJECT); Content textBody = new Content().WithData(BODY); Body body = new Body().WithText(textBody); // Create a message with the specified subject and body. Message message = new Message().WithSubject(subject).WithBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().WithSource(FROM).WithDestination(destination).WithMessage(message); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(); SendEmailResponse response = client.SendEmail(request); Console.WriteLine("Sent successfully."); } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Method to send email through cloud service. /// If isHtml is true the body is interpreted as HTML content. /// </summary> public bool SendBulkEmail(string subject, string bodyText, string fromAddress, List<string> toAddresses, List<string> ccAddresses, List<string> replyToAddresses, bool isHtml) { try { if (replyToAddresses == null || replyToAddresses.Count == 0) { replyToAddresses = new List<string>(); replyToAddresses.Add(fromAddress); } Message message = new Message(); message.Body = new Body(); Content bodyContent = new Content(); bodyContent.Charset = "UTF-8"; bodyContent.Data = bodyText; if (isHtml) message.Body.Html = bodyContent; else message.Body.Text = bodyContent; Content subjectContent = new Content(); subjectContent.Charset = "UTF-8"; subjectContent.Data = subject; message.Subject = subjectContent; Destination destination = new Destination(toAddresses); if (ccAddresses != null && ccAddresses.Count > 0) destination.CcAddresses = ccAddresses; SendEmailRequest sendEmailRequest = new SendEmailRequest() .WithDestination(destination) .WithMessage(message) .WithReplyToAddresses(replyToAddresses) .WithSource(fromAddress); //Create AWS Client AmazonSimpleEmailService amazonSes = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(this.cloudServiceConfigProvider.AWSAccessKeyId, this.cloudServiceConfigProvider.AWSSecretKey); //Send email SendEmailResponse sendEmailResponse = amazonSes.SendEmail(sendEmailRequest); return true; } catch (Exception) { ///TODO: Write log 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 Message WithSubject(Content subject) { this.subject = subject; return this; }
/// <summary> /// Constructs a new Body object. /// Callers should use the properties or fluent setter (With...) methods to /// initialize any additional object members. /// </summary> /// /// <param name="text"> The content of the message, in text format. Use this for text-based email clients, or clients on high-latency networks /// (such as mobile devices). </param> public Body(Content text) { this.text = text; }
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 void SendEmail(string fromEmailAddress, string fromFriendlyName, string toEmailAddress, string emailSubject, string emailBody) { /* var client = new AmazonSimpleEmailServiceClient(Settings.Default.AWSAccessKey, Settings.Default.AWSSecretKey, Amazon.RegionEndpoint.EUWest1); var client = new AmazonSimpleEmailServiceClient("AKIAIJINFUWK57TVYABQ", "AosdbK3YfN8zvFltHNDuxFZrHVZNlLeBZQ1pGKG8dFCd", Amazon.RegionEndpoint.EUWest1); */ /* var destination = new Destination(new List<string>() {toEmailAddress}); var subjectContent = new Content(subject); var bodyContent = new Content(body); var messageBody = new Body(bodyContent); var message = new Message(subjectContent, messageBody); var request = new SendEmailRequest(fromEmailAddress, destination, message); client.SendEmail(request); */ String FROM = fromEmailAddress; // Replace with your "From" address. This address must be verified. String TO = toEmailAddress; // Replace with a "To" address. If you have not yet requested // production access, this address must be verified. const String SUBJECT = "Amazon SES test (AWS SDK for .NET)"; const String BODY = "This email was sent through Amazon SES by using the AWS SDK for .NET."; // Construct an object to contain the recipient address. Destination destination = new Destination(); destination.ToAddresses = (new List<string>() { TO }); // Create the subject and body of the message. Content subject = new Content(SUBJECT); Content textBody = new Content(BODY); Body body = new Body(textBody); // Create a message with the specified subject and body. Message message = new Message(subject, body); // Assemble the email. SendEmailRequest request = new SendEmailRequest(FROM, destination, message); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are USWest2 // and EUWest1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.EUWest1; // Instantiate an Amazon SES client, which will make the service call. var client = new AmazonSimpleEmailServiceClient(Settings.Default.AWSAccessKey, Settings.Default.AWSSecretKey, Amazon.RegionEndpoint.EUWest1); // Send the email. // client.VerifyEmailAddress(new VerifyEmailAddressRequest() {EmailAddress = fromEmailAddress}); client.SendEmail(request); Console.WriteLine("Email sent!"); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // 尝试注册用户 MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { //Send email by amazon ses string accessKey = "AKIAIO4BEQ2UGFAMHRFQ"; string secretAccessKey = "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"; AmazonSimpleEmailServiceConfig amazonConfiguration = new AmazonSimpleEmailServiceConfig(); AmazonSimpleEmailServiceClient clientMail = new AmazonSimpleEmailServiceClient(accessKey, secretAccessKey, amazonConfiguration); Destination destination = new Destination(); destination.ToAddresses.Add(model.Email); Body body = new Body() { Html = new Content("Welcome to AIRPDF "+"Your account is: "+model.UserName+" Your password is: "+model.ConfirmPassword) }; Content subject = new Content("Welcome to AIRPDF!"); Message message = new Message(subject, body); SendEmailRequest sendEmailRequest = new SendEmailRequest("*****@*****.**", destination, message); clientMail.SendEmail(sendEmailRequest); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "pdf"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return View(model); }