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); }
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 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 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 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; } } }
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); } }
/// <summary> /// The send mail. /// </summary> /// <param name="from"> /// The from. /// </param> /// <param name="to"> /// The to. /// </param> /// <param name="subject"> /// The subject. /// </param> /// <param name="body"> /// The body. /// </param> public void SendMail(string @from, string to, string subject, string body) { using (var client = Amazon.AWSClientFactory.CreateAmazonSimpleEmailServiceClient(this.credentials)) { var request = new SendEmailRequest(); var destination = new Destination(to.Split(';', ',').ToList()); request.WithDestination(destination); request.WithSource(@from); var message = new Message(); message.WithSubject(new Content(subject)); var html = new Body { Html = new Content(body) }; message.WithBody(html); request.WithMessage(message); request.WithReturnPath("*****@*****.**"); client.SendEmail(request); } }
/// <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 void Enviar() { var body = new Body().WithText(new Content(_log.ToString())); var mess = new Message( new Content("Backup " + DateTime.Now.ToString("dd/MM/yyyy hh:mm")), body); var req = new SendEmailRequest("*****@*****.**", new Destination().WithToAddresses(_destinos), mess); try { _client.SendEmail(req); } catch(Exception ex) { Console.Out.Write(_log.ToString()); } }
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 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; }
private ASM.Message CreateMessage(IEmailMessage message) { string subjectText = !string.IsNullOrEmpty(message.Subject) ? message.Subject : "General enquiry"; var subject = new ASM.Content(); subject.Charset = _charset; subject.Data = subjectText; var text = new ASM.Content(); text.Charset = _charset; text.Data = message.Text; var body = new ASM.Body(); body.Text = text; var awsMessage = new ASM.Message(); awsMessage.Body = body; awsMessage.Subject = subject; return(awsMessage); }
//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> /// 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 Message WithBody(Body body) { this.body = body; return this; }
//Send notification to user via email. /// <summary> /// Uses SES to send an email to a user. /// </summary> /// <param name="userID">The user being sent the email</param> /// <param name="inputSubject">The subject of the email</param> /// <param name="inputBody">The body of the email</param> public static void SendEmail(int userID, string inputSubject, string inputBody) { try { String email = (from userprofiles in userDb.UserProfiles where userprofiles.UserId == userID select userprofiles.Email).FirstOrDefault(); ; //Find userID's email address. if (inputSubject == "") { inputSubject = "The Cookbook - New Notification Waiting For You"; } if (inputBody == "") { inputBody = "You have received a new notification. Visit The Cookbook for more information."; } 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 = inputSubject; String BODY = inputBody; // 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); } }
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; }
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!"); }
/// <summary> /// Send the email message /// </summary> /// <param name="messageBody">the body text to include in the mail</param> protected virtual void SendEmail(string messageBody) { // Create the email object first, then add the properties. var subject = new Content(Subject); Body body = new Body(); if (IsBodyHTML) { body.Html = new Content(messageBody); } else { body.Text = new Content(messageBody); } var destination = new Destination(); var msg = new Message(subject, body); destination.ToAddresses = m_to.Split(ADDRESS_DELIMITERS).ToList(); if (!String.IsNullOrWhiteSpace(m_cc)) { destination.CcAddresses = m_cc.Split(ADDRESS_DELIMITERS).ToList(); } if (!String.IsNullOrWhiteSpace(m_bcc)) { destination.BccAddresses = m_bcc.Split(ADDRESS_DELIMITERS).ToList(); } var request = new SendEmailRequest(From, destination, msg); var credentials = new Amazon.Runtime.BasicAWSCredentials(AccessKey, SecretKey); var client = new AmazonSimpleEmailServiceClient(credentials, Amazon.RegionEndpoint.EUWest1); try { client.SendEmailAsync(request); } catch (Exception ex) { ErrorHandler.Error("Error occurred while sending e-mail notification.", ex); } }
/// <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; }
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 SendStatus SendEmail(MailMessage mailMessage) { //Check if we need to query stats RefreshQuotaIfNeeded(); if (_quota != null) { lock (SynchRoot) { if (_quota.Max24HourSend <= _quota.SentLast24Hours) { //Quota exceeded //Queu next refresh to +24 hours _lastRefresh = DateTime.UtcNow.AddHours(24); _log.WarnFormat("quota limit reached. setting next check to: {0}", _lastRefresh); return SendStatus.QuotaLimit; } } } var destination = new Destination { ToAddresses = mailMessage.To.Select(adresses => adresses.Address).ToList(), BccAddresses = mailMessage.Bcc.Select(adresses => adresses.Address).ToList(), CcAddresses = mailMessage.CC.Select(adresses => adresses.Address).ToList(), }; var body = new Body(new Content(mailMessage.Body) { Charset = Encoding.UTF8.WebName }); if (mailMessage.AlternateViews.Count > 0) { //Get html body foreach (var alternateView in mailMessage.AlternateViews) { if ("text/html".Equals(alternateView.ContentType.MediaType, StringComparison.OrdinalIgnoreCase)) { var stream = alternateView.ContentStream; var buf = new byte[stream.Length]; stream.Read(buf, 0, buf.Length); stream.Seek(0, SeekOrigin.Begin);//NOTE:seek to begin to keep HTML body body.Html = new Content(Encoding.UTF8.GetString(buf)) { Charset = Encoding.UTF8.WebName }; break; } } } var message = new Message(new Content(mailMessage.Subject), body); var seRequest = new SendEmailRequest(mailMessage.From.ToEncodedStringEx(), destination, message); if (mailMessage.ReplyTo != null) seRequest.ReplyToAddresses.Add(mailMessage.ReplyTo.Address); ThrottleIfNeeded(); var response = _emailService.SendEmail(seRequest); _lastSend = DateTime.UtcNow; return response != null ? SendStatus.Ok : SendStatus.Failed; }
/// <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; }
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); }
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; }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.SimpleEmail.Model.SendEmailRequest(); if (cmdletContext.ConfigurationSetName != null) { request.ConfigurationSetName = cmdletContext.ConfigurationSetName; } // populate Destination var requestDestinationIsNull = true; request.Destination = new Amazon.SimpleEmail.Model.Destination(); List <System.String> requestDestination_destination_BccAddress = null; if (cmdletContext.Destination_BccAddress != null) { requestDestination_destination_BccAddress = cmdletContext.Destination_BccAddress; } if (requestDestination_destination_BccAddress != null) { request.Destination.BccAddresses = requestDestination_destination_BccAddress; requestDestinationIsNull = false; } List <System.String> requestDestination_destination_CcAddress = null; if (cmdletContext.Destination_CcAddress != null) { requestDestination_destination_CcAddress = cmdletContext.Destination_CcAddress; } if (requestDestination_destination_CcAddress != null) { request.Destination.CcAddresses = requestDestination_destination_CcAddress; requestDestinationIsNull = false; } List <System.String> requestDestination_destination_ToAddress = null; if (cmdletContext.Destination_ToAddress != null) { requestDestination_destination_ToAddress = cmdletContext.Destination_ToAddress; } if (requestDestination_destination_ToAddress != null) { request.Destination.ToAddresses = requestDestination_destination_ToAddress; requestDestinationIsNull = false; } // determine if request.Destination should be set to null if (requestDestinationIsNull) { request.Destination = null; } // populate Message var requestMessageIsNull = true; request.Message = new Amazon.SimpleEmail.Model.Message(); Amazon.SimpleEmail.Model.Body requestMessage_message_Body = null; // populate Body var requestMessage_message_BodyIsNull = true; requestMessage_message_Body = new Amazon.SimpleEmail.Model.Body(); Amazon.SimpleEmail.Model.Content requestMessage_message_Body_message_Body_Html = null; // populate Html var requestMessage_message_Body_message_Body_HtmlIsNull = true; requestMessage_message_Body_message_Body_Html = new Amazon.SimpleEmail.Model.Content(); System.String requestMessage_message_Body_message_Body_Html_html_Charset = null; if (cmdletContext.Html_Charset != null) { requestMessage_message_Body_message_Body_Html_html_Charset = cmdletContext.Html_Charset; } if (requestMessage_message_Body_message_Body_Html_html_Charset != null) { requestMessage_message_Body_message_Body_Html.Charset = requestMessage_message_Body_message_Body_Html_html_Charset; requestMessage_message_Body_message_Body_HtmlIsNull = false; } System.String requestMessage_message_Body_message_Body_Html_html_Data = null; if (cmdletContext.Html_Data != null) { requestMessage_message_Body_message_Body_Html_html_Data = cmdletContext.Html_Data; } if (requestMessage_message_Body_message_Body_Html_html_Data != null) { requestMessage_message_Body_message_Body_Html.Data = requestMessage_message_Body_message_Body_Html_html_Data; requestMessage_message_Body_message_Body_HtmlIsNull = false; } // determine if requestMessage_message_Body_message_Body_Html should be set to null if (requestMessage_message_Body_message_Body_HtmlIsNull) { requestMessage_message_Body_message_Body_Html = null; } if (requestMessage_message_Body_message_Body_Html != null) { requestMessage_message_Body.Html = requestMessage_message_Body_message_Body_Html; requestMessage_message_BodyIsNull = false; } Amazon.SimpleEmail.Model.Content requestMessage_message_Body_message_Body_Text = null; // populate Text var requestMessage_message_Body_message_Body_TextIsNull = true; requestMessage_message_Body_message_Body_Text = new Amazon.SimpleEmail.Model.Content(); System.String requestMessage_message_Body_message_Body_Text_text_Charset = null; if (cmdletContext.Text_Charset != null) { requestMessage_message_Body_message_Body_Text_text_Charset = cmdletContext.Text_Charset; } if (requestMessage_message_Body_message_Body_Text_text_Charset != null) { requestMessage_message_Body_message_Body_Text.Charset = requestMessage_message_Body_message_Body_Text_text_Charset; requestMessage_message_Body_message_Body_TextIsNull = false; } System.String requestMessage_message_Body_message_Body_Text_text_Data = null; if (cmdletContext.Text_Data != null) { requestMessage_message_Body_message_Body_Text_text_Data = cmdletContext.Text_Data; } if (requestMessage_message_Body_message_Body_Text_text_Data != null) { requestMessage_message_Body_message_Body_Text.Data = requestMessage_message_Body_message_Body_Text_text_Data; requestMessage_message_Body_message_Body_TextIsNull = false; } // determine if requestMessage_message_Body_message_Body_Text should be set to null if (requestMessage_message_Body_message_Body_TextIsNull) { requestMessage_message_Body_message_Body_Text = null; } if (requestMessage_message_Body_message_Body_Text != null) { requestMessage_message_Body.Text = requestMessage_message_Body_message_Body_Text; requestMessage_message_BodyIsNull = false; } // determine if requestMessage_message_Body should be set to null if (requestMessage_message_BodyIsNull) { requestMessage_message_Body = null; } if (requestMessage_message_Body != null) { request.Message.Body = requestMessage_message_Body; requestMessageIsNull = false; } Amazon.SimpleEmail.Model.Content requestMessage_message_Subject = null; // populate Subject var requestMessage_message_SubjectIsNull = true; requestMessage_message_Subject = new Amazon.SimpleEmail.Model.Content(); System.String requestMessage_message_Subject_subject_Charset = null; if (cmdletContext.Subject_Charset != null) { requestMessage_message_Subject_subject_Charset = cmdletContext.Subject_Charset; } if (requestMessage_message_Subject_subject_Charset != null) { requestMessage_message_Subject.Charset = requestMessage_message_Subject_subject_Charset; requestMessage_message_SubjectIsNull = false; } System.String requestMessage_message_Subject_subject_Data = null; if (cmdletContext.Subject_Data != null) { requestMessage_message_Subject_subject_Data = cmdletContext.Subject_Data; } if (requestMessage_message_Subject_subject_Data != null) { requestMessage_message_Subject.Data = requestMessage_message_Subject_subject_Data; requestMessage_message_SubjectIsNull = false; } // determine if requestMessage_message_Subject should be set to null if (requestMessage_message_SubjectIsNull) { requestMessage_message_Subject = null; } if (requestMessage_message_Subject != null) { request.Message.Subject = requestMessage_message_Subject; requestMessageIsNull = false; } // determine if request.Message should be set to null if (requestMessageIsNull) { request.Message = null; } if (cmdletContext.ReplyToAddress != null) { request.ReplyToAddresses = cmdletContext.ReplyToAddress; } if (cmdletContext.ReturnPath != null) { request.ReturnPath = cmdletContext.ReturnPath; } if (cmdletContext.ReturnPathArn != null) { request.ReturnPathArn = cmdletContext.ReturnPathArn; } if (cmdletContext.Source != null) { request.Source = cmdletContext.Source; } if (cmdletContext.SourceArn != null) { request.SourceArn = cmdletContext.SourceArn; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }