public static void Main(string[] args) { if (checkRequiredFields()) { NameValueCollection appConfig = ConfigurationManager.AppSettings; string accessKeyID = appConfig["AWSAccessKey"]; string secretAccessKeyID = appConfig["AWSSecretKey"]; theClient = new AmazonSimpleEmailServiceClient(accessKeyID, secretAccessKeyID); int myTimeToSleep = 30000; if (args.Count<string>() == 1) { myTimeToSleep = Int16.Parse(args[0]); } ConsoleMessageWithDate("Started Automated Email with a delay of " + myTimeToSleep); IEmailService myEmailService = new EmailService(); while (true) { myEmailService.SendEmails(theClient); Thread.Sleep(myTimeToSleep); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public static void SESSendRawEmail() { #region SESSendRawEmail // using System.IO; var sesClient = new AmazonSimpleEmailServiceClient(); var stream = new MemoryStream( Encoding.UTF8.GetBytes("From: [email protected]\n" + "To: [email protected]\n" + "Subject: You're invited to the meeting\n" + "Content-Type: text/plain\n\n" + "Please join us Monday at 7:00 PM.") ); var raw = new RawMessage { Data = stream }; var to = new List<string>() { "*****@*****.**" }; var from = "*****@*****.**"; var request = new SendRawEmailRequest { Destinations = to, RawMessage = raw, Source = from }; sesClient.SendRawEmail(request); #endregion }
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; } } }
static void Main(string[] args) { if (CheckRequiredFields()) { using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USEast1)) { var sendRequest = new SendEmailRequest { Source = senderAddress, Destination = new Destination { ToAddresses = new List<string> { receiverAddress } }, Message = new Message { Subject = new Content("Sample Mail using SES"), Body = new Body { Text = new Content("Sample message content.") } } }; try { Console.WriteLine("Sending email using AWS SES..."); var response = client.SendEmail(sendRequest); Console.WriteLine("The email was sent successfully."); } catch (Exception ex) { Console.WriteLine("The email was not sent."); Console.WriteLine("Error message: " + ex.Message); } } } Console.Write("Press any key to continue..."); Console.ReadKey(); }
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 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 override void Init(IDictionary<string, string> properties) { base.Init(properties); ses = new AmazonSimpleEmailServiceClient(properties["accessKey"], properties["secretKey"]); refreshTimeout = TimeSpan.Parse(properties.ContainsKey("refreshTimeout") ? properties["refreshTimeout"] : "0:30:0"); lastRefresh = DateTime.UtcNow - refreshTimeout; //set to refresh on first send }
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()); } } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button> (Resource.Id.myButton); button.Click += delegate { const string ACCESS_KEY = ""; const string SECRET_KEY = ""; const string YOUR_EMAIL = ""; AmazonSimpleEmailServiceClient sesClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1); var Name = FindViewById<EditText>(Resource.Id.name); var Rating = FindViewById<RatingBar>(Resource.Id.ratingBar); var Comments = FindViewById<EditText>(Resource.Id.comments); var messageBody = new Amazon.SimpleEmail.Model.Content (String.Format("Rating: {0}\n\nComments:\n{1}", Rating.Selected, Comments.Text)); var body = new Amazon.SimpleEmail.Model.Body (messageBody); var subject = new Amazon.SimpleEmail.Model.Content (String.Format ("Feedback from {0}", Name.Text)); var message = new Amazon.SimpleEmail.Model.Message (subject, body); var destination = new Amazon.SimpleEmail.Model.Destination (new System.Collections.Generic.List<string> (){ YOUR_EMAIL }); var sendEmailRequest = new Amazon.SimpleEmail.Model.SendEmailRequest (YOUR_EMAIL, destination, message); sesClient.SendEmail (sendEmailRequest); }; }
public override void Init(IDictionary<string, string> properties) { base.Init(properties); var region = properties.ContainsKey("region") ? RegionEndpoint.GetBySystemName(properties["region"]): RegionEndpoint.USEast1; ses = new AmazonSimpleEmailServiceClient(properties["accessKey"], properties["secretKey"], region); refreshTimeout = TimeSpan.Parse(properties.ContainsKey("refreshTimeout") ? properties["refreshTimeout"] : "0:30:0"); lastRefresh = DateTime.UtcNow - refreshTimeout; //set to refresh on first send }
public AWSEmail() { var accessKey = ConfigurationManager.AppSettings["ses.accessKey"]; var secretKey = ConfigurationManager.AppSettings["ses.secretKey"]; _emailService = new AmazonSimpleEmailServiceClient(accessKey, secretKey); }
//From E-mail address must be verified through Amazon /// <param name="AWSAccessKey">public key associated with our Amazon Account</param> /// <param name="AWSSecretKey">private key associated with our Amazon Account</param> /// <param name="ToEmail">Who do you want to send the E-mail to, seperate multiple addresses with a comma</param> /// <param name="FromEmail">Who is the e-mail from, this must be a verified e-mail address through Amazon</param> /// <param name="Subject">Subject of e-mail</param> /// <param name="Content">Text for e-mail</param> public void SendEmail(string AWSAccessKey, string AWSSecretKey, string ToEmail, string FromEmail, string Subject, string Content) { Amazon.SimpleEmail.AmazonSimpleEmailServiceClient client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient(AWSAccessKey, AWSSecretKey); SendEmailRequest em = new SendEmailRequest() .WithDestination(new Destination() { BccAddresses = new List<String>() { ToEmail } }) .WithSource(FromEmail) .WithMessage(new Message(new Content(Subject), new Body().WithText(new Content(Content)))); SendEmailResponse response = client.SendEmail(em); }
public static string sendInvEmail(string email, string subject, string msg, string attach1, string attach2) { try { Amazon.SimpleEmail.AmazonSimpleEmailServiceConfig config = new Amazon.SimpleEmail.AmazonSimpleEmailServiceConfig(); config.RegionEndpoint = Amazon.RegionEndpoint.USEast1; Amazon.SimpleEmail.AmazonSimpleEmailServiceClient client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient("AKIAI6NU4VLLI32AI2UA", Cryptography.Decrypt("NdL0xWLhvbF6pvu3hw1FtluhPmUc1jAuWKgj6mb4V89KztEq6MjEhQoiCPLVv4y9"), config); var stream = new MemoryStream(); MimeMessage objMessage = new MimeMessage(); string[] emls = email.Split(','); foreach (string eml in emls) { objMessage.To.Add(new MailboxAddress(string.Empty, eml)); } objMessage.From.Add(new MailboxAddress("InfnIT Invoice", "*****@*****.**")); objMessage.Subject = subject; BodyBuilder emailBodyObj = new BodyBuilder(); emailBodyObj.HtmlBody = msg; emailBodyObj.Attachments.Add(attach1); emailBodyObj.Attachments.Add(attach2); objMessage.Body = emailBodyObj.ToMessageBody(); objMessage.WriteTo(stream); Amazon.SimpleEmail.Model.SendRawEmailRequest mailObj = new Amazon.SimpleEmail.Model.SendRawEmailRequest(new RawMessage(stream)); SendRawEmailResponse response = client.SendRawEmail(mailObj); string res = response.MessageId; System.Net.Mail.MailMessage aMessage = new System.Net.Mail.MailMessage(); aMessage.From = new System.Net.Mail.MailAddress("*****@*****.**", "InfnIT Invoice"); //aMessage.To.Add(email); //aMessage.ReplyTo = new System.Net.Mail.MailAddress("*****@*****.**"); //aMessage.Subject = subject; //System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(msg, System.Text.Encoding.UTF8, "text/html"); //aMessage.IsBodyHtml = true; //aMessage.BodyEncoding = System.Text.Encoding.UTF8; //aMessage.Attachments.Add(new System.Net.Mail.Attachment(attach1)); //aMessage.Attachments.Add(new System.Net.Mail.Attachment(attach2)); //aMessage.AlternateViews.Add(htmlView); //System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); //mailClient.Host = "smtp.gmail.com"; //mailClient.Port = 587; //mailClient.EnableSsl = true; //mailClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "m4iling2"); //mailClient.Send(aMessage); return("success");//downloadCfdi += "<p>Correo enviado"; } catch (Exception ex) { return(ex.Message); //downloadCfdi += "<p><i class=\"w3-red\">No se pudo enviar el correo: +" + ex.Message + "</i>"; } }
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); } }
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; }
/// <summary> /// Retrieves SES statistics for the AWS account /// </summary> /// <returns></returns> public GetSendStatisticsResult getSendStats() { GetSendStatisticsResult ret = null; using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_accessKeyID, _secretAccessKeyID)) { GetSendStatisticsRequest request = new GetSendStatisticsRequest(); GetSendStatisticsResponse response = client.GetSendStatistics(request); ret = response.GetSendStatisticsResult; } return ret; }
/// <summary> /// Lists email addresses capable of sending emails thru SES /// </summary> /// <returns></returns> public ListVerifiedEmailAddressesResult listVerifiedEmails() { ListVerifiedEmailAddressesResult ret = null; using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_accessKeyID, _secretAccessKeyID)) { ListVerifiedEmailAddressesRequest request = new ListVerifiedEmailAddressesRequest(); ListVerifiedEmailAddressesResponse response = client.ListVerifiedEmailAddresses(request); ret = response.ListVerifiedEmailAddressesResult; } return ret; }
public static void Send(string from, string to, string bcc, string subject, string body) { using (var client = new AmazonSimpleEmailServiceClient(Settings.AccessKey, Settings.Secret, RegionEndpoint.USWest2)) { var request = new SendRawEmailRequest { Source = from, Destinations = new List<string> { to, bcc }, RawMessage = CreateMessage(from, to, bcc, subject, body) }; client.SendRawEmail(request); } }
public async Task Send(Indulgence indulgence, string indulgenceFilePath) { service = new AmazonSimpleEmailServiceClient( ConfigurationManager.AppSettings["awsAccessKeyId"], ConfigurationManager.AppSettings["awsAccessSecret"]); SendEmailRequest request = new SendEmailRequest(); request.Destination = BuildDestination(); request.Message=BuildMessage(indulgence); request.Source="*****@*****.**"; var response = service.SendEmail(request); }
public async Task Send(Indulgence indulgence, string indulgenceFilePath) { service = new AmazonSimpleEmailServiceClient( ConfigurationManager.AppSettings["awsAccessKeyId"], ConfigurationManager.AppSettings["awsAccessSecret"]); SendEmailRequest request = new SendEmailRequest(); request.Destination = BuildDestination(); request.Message = BuildMessage(indulgence); request.Source = "*****@*****.**"; var response = service.SendEmail(request); }
public static void SESGetSendQuota() { #region SESGetSendQuota var sesClient = new AmazonSimpleEmailServiceClient(); var response = sesClient.GetSendQuota(); Console.WriteLine("Maximum emails that can be sent each 24 hours: " + response.Max24HourSend); Console.WriteLine("Maximum emails that can be sent per second: " + response.MaxSendRate); Console.WriteLine("Number of emails sent in last 24 hours: " + response.SentLast24Hours); #endregion Console.ReadLine(); }
/// <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; } }
void HandleTouchUpInside (object sender, EventArgs e) { const string ACCESS_KEY = ""; const string SECRET_KEY = ""; const string YOUR_EMAIL = ""; AmazonSimpleEmailServiceClient sesClient = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1); var messageBody = new Amazon.SimpleEmail.Model.Content (String.Format("Rating: {0}\n\nComments:\n{1}", Rating.SelectedSegment, Comments.Text)); var body = new Amazon.SimpleEmail.Model.Body (messageBody); var subject = new Amazon.SimpleEmail.Model.Content (String.Format ("Feedback from {0}", Name.Text)); var message = new Amazon.SimpleEmail.Model.Message (subject, body); var destination = new Amazon.SimpleEmail.Model.Destination (new System.Collections.Generic.List<string> (){ YOUR_EMAIL }); var sendEmailRequest = new Amazon.SimpleEmail.Model.SendEmailRequest (YOUR_EMAIL, destination, message); sesClient.SendEmail (sendEmailRequest); }
public bool DeleteEmailAddress(string email) { client = new AmazonSimpleEmailServiceClient(AccessKey, SecretKey); bool result = false; Amazon.SimpleEmail.Model.DeleteVerifiedEmailAddressRequest request = new Amazon.SimpleEmail.Model.DeleteVerifiedEmailAddressRequest(); Amazon.SimpleEmail.Model.DeleteVerifiedEmailAddressResponse response = new Amazon.SimpleEmail.Model.DeleteVerifiedEmailAddressResponse(); if (client != null) { request.EmailAddress = email.Trim(); response = client.DeleteVerifiedEmailAddress(request); if (!string.IsNullOrEmpty(response.ResponseMetadata.RequestId)) { result = true; } } return result; }
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 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 SendEmailAdditionalMemberInvitation(string email, string inviterName, string url) { var bodyContent = "Your household member " + inviterName + " sent you this <a href='" + url + "'>link</a> to join Green Money."; var recipientEmail = SetRecipientEmail(email); // create email request var request = new SendEmailRequest() .WithDestination(new Destination(new List<string> { recipientEmail })) .WithSource("*****@*****.**") .WithReturnPath("*****@*****.**") .WithMessage(new Message() .WithSubject(new Content("GreenMoney. Household member invitation")) .WithBody(new Body().WithHtml(new Content(bodyContent))) ); //send it var client = new AmazonSimpleEmailServiceClient("AKIAIDP5FFSCJUHHC4QA", "NKAzwbtwwhvKuQZj2t6OXxOhaOEuaBYh3E34Jxbs"); 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; } }
static void Main(string[] args) { Console.WriteLine("Press any key to send mail!"); Console.ReadKey(); //Getting AWS credentials from App.config //note: see the app.config to get a example var credentials = new EnvironmentAWSCredentials(); //Client SES instantiated var client = new AmazonSimpleEmailServiceClient(credentials, RegionEndpoint.USEast1); var mimeMessage = new MimeMessage(); //Add sender e-mail address //Note: this e-mail address must to be allowed and checked by AWS SES mimeMessage.From.Add(new MailboxAddress("Test Sender", "*****@*****.**")); //Add e-mail address destiny mimeMessage.To.Add(new MailboxAddress("Joel", "*****@*****.**")); mimeMessage.Subject = "Test"; //Getting attachment stream var fileBytes = File.ReadAllBytes(@"C:\anyfile.pdf"); var bodyBuilder = new BodyBuilder(); bodyBuilder.TextBody = "Testing the body message"; //You must to inform the mime-type of the attachment and his name bodyBuilder.Attachments.Add("AnyAttachment.pdf", fileBytes, new ContentType("application", "pdf")); mimeMessage.Body = bodyBuilder.ToMessageBody(); //Map MimeMessage to MemoryStream, that is what SenRawEmailRequest accepts var rawMessage = new MemoryStream(); mimeMessage.WriteTo(rawMessage); client.SendRawEmail(new SendRawEmailRequest(new RawMessage(rawMessage))); Console.WriteLine("Email Sended"); Console.ReadKey(); }
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 static void SendVerificationEmail(string emailaddress, string validation_guid) { const string VERIFICATION_DOMAIN = "https://nzixo03fx1.execute-api.us-west-2.amazonaws.com/prod/emailvalidation?verificationstring="; //TODO: Move this to our domain name prior to launch const string FROM = "*****@*****.**"; //TODO: Change to real domain name const string SUBJECT = "Please verify your email address"; string TO = emailaddress; string mBase64EncodedGuid = Convert.ToBase64String(Encoding.UTF8.GetBytes(emailaddress + ":" + validation_guid)); var message = new MimeMessage(); message.From.Add(new MailboxAddress("GEM CARRY EMAIL VERIFICATION", FROM)); message.To.Add(new MailboxAddress("New Gamer", TO)); message.Subject = SUBJECT; var builder = new BodyBuilder(); builder.TextBody = string.Format("To activate your account, please click the following link to verifiy your email address {0}{1}", VERIFICATION_DOMAIN, mBase64EncodedGuid); builder.HtmlBody = string.Format("To activate your account, please click <a href={0}{1}> here</a> to verify your email address.",VERIFICATION_DOMAIN,mBase64EncodedGuid); message.Body = builder.ToMessageBody(); var stream = new MemoryStream(); message.WriteTo(stream); try { AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(); var request = new SendRawEmailRequest { RawMessage = new RawMessage { Data = stream } }; client.SendRawEmail(request); #if DEBUG logger.WriteLog(GameLogger.LogLevel.Debug, string.Format("Generating Validation Email for {0}.", emailaddress)); #endif // DEBUG } catch (Exception ex) { logger.WriteLog(GameLogger.LogLevel.Error, ex.Message.ToString()); } }