static void Main(string[] args) { //Remember to enter your (AWSAccessKeyID, AWSSecretAccessKey) if not using and IAM User with credentials assigned to your instance and your RegionEndpoint using (var client = new AmazonSimpleEmailServiceClient("YourAWSAccessKeyID", "YourAWSSecretAccessKey", RegionEndpoint.USEast1)) using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var builder = new BodyBuilder() { TextBody = "Hello World" }; message.From.Add(new MailboxAddress("*****@*****.**")); message.To.Add(new MailboxAddress("*****@*****.**")); message.Subject = "Hello World"; //I'm using the stream method, but you don't have to. using (FileStream stream = File.Open(@"Attachment1.pdf", FileMode.Open)) builder.Attachments.Add("Attachment1.pdf", stream); using (FileStream stream = File.Open(@"Attachment2.pdf", FileMode.Open)) builder.Attachments.Add("Attachment2.pdf", stream); message.Body = builder.ToMessageBody(); message.WriteTo(messageStream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = messageStream } }; client.SendRawEmail(request); } }
/// <summary> /// <para>Sends an email message, with header and content specified by the client. The <c>SendRawEmail</c> action is useful for sending /// multipart MIME emails. The raw text of the message must comply with Internet email standards; otherwise, the message cannot be sent. </para> /// <para><b>IMPORTANT:</b> You can only send email from verified email addresses and domains. If you have not requested production access to /// Amazon SES, you must also verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator. For /// more information, go to the Amazon SES Developer Guide. </para> <para>The total size of the message cannot exceed 10 MB. This includes any /// attachments that are part of the message.</para> <para>Amazon SES has a limit on the total number of recipients per message: The combined /// number of To:, CC: and BCC: email addresses cannot exceed 50. If you need to send an email message to a larger audience, you can divide your /// recipient list into groups of 50 or fewer, and then call Amazon SES repeatedly to send the message to each group. </para> <para>For every /// message that you send, the total number of recipients (To:, CC: and BCC:) is counted against your <i>sending quota</i> - the maximum number /// of emails you can send in a 24-hour period. For information about your sending quota, go to the <a href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/manage-sending-limits.html">Amazon SES Developer Guide</a> . /// </para> /// </summary> /// /// <param name="sendRawEmailRequest">Container for the necessary parameters to execute the SendRawEmail service method on /// AmazonSimpleEmailService.</param> /// /// <returns>The response from the SendRawEmail service method, as returned by AmazonSimpleEmailService.</returns> /// /// <exception cref="T:Amazon.SimpleEmail.Model.MessageRejectedException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task <SendRawEmailResponse> SendRawEmailAsync(SendRawEmailRequest sendRawEmailRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SendRawEmailRequestMarshaller(); var unmarshaller = SendRawEmailResponseUnmarshaller.GetInstance(); return(Invoke <IRequest, SendRawEmailRequest, SendRawEmailResponse>(sendRawEmailRequest, marshaller, unmarshaller, signer, cancellationToken)); }
private void SendEmailWithAttachments(IAmazonSimpleEmailService client) { using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var builder = new BodyBuilder { TextBody = "Hello World" }; message.From.Add(new MailboxAddress(SenderAddress)); message.To.Add(new MailboxAddress(ReceiverAddress)); message.Subject = "Hello World"; using (var stream = File.Open(@"C:\Users\dkaushikl\Documents\Visual Studio 2015\Projects\DemoAmazon\DemoAmazon\pdf\pdf.pdf", FileMode.Open)) builder.Attachments.Add(@"C:\Users\dkaushikl\Documents\Visual Studio 2015\Projects\DemoAmazon\DemoAmazon\pdf\pdf.pdf", stream); using (var stream = File.Open(@"C:\Users\dkaushikl\Documents\Visual Studio 2015\Projects\DemoAmazon\DemoAmazon\pdf\pdf-sample.pdf", FileMode.Open)) builder.Attachments.Add(@"C:\Users\dkaushikl\Documents\Visual Studio 2015\Projects\DemoAmazon\DemoAmazon\pdf\pdf-sample.pdf", stream); message.Body = builder.ToMessageBody(); message.WriteTo(messageStream); var request = new SendRawEmailRequest { RawMessage = new RawMessage { Data = messageStream } }; client.SendRawEmail(request); } }
private async Task <SendRawEmailResponse> SendEmail(EmailMessage emailMessage) { var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(_emailBuilder.BuildMessageToStream(emailMessage)) }; try { SendRawEmailResponse response = new SendRawEmailResponse { HttpStatusCode = HttpStatusCode.OK }; if (_sendAmazonEmails) { response = await _amazonSimpleEmailService.SendRawEmailAsync(sendRequest); } LogResponse(response); return(response); } catch (Exception exception) { _logger.LogError($"An error occurred trying to send an email to Amazon SES. \n{exception.Message}"); return(new SendRawEmailResponse { HttpStatusCode = HttpStatusCode.BadRequest }); } }
internal SendRawEmailResponse SendRawEmail(SendRawEmailRequest request) { var marshaller = new SendRawEmailRequestMarshaller(); var unmarshaller = SendRawEmailResponseUnmarshaller.Instance; return(Invoke <SendRawEmailRequest, SendRawEmailResponse>(request, marshaller, unmarshaller)); }
public async Task AmazonEmailSendAsync(string userToaddress, string subject, string body) { try { var builder = new BodyBuilder(); string EmailConfirmationCode = RandomString(10, false); builder.HtmlBody = body; var oMessage = new MimeMessage(); oMessage.From.Add(new MailboxAddress("Autumn", "")); oMessage.To.Add(new MailboxAddress(userToaddress)); oMessage.Subject = subject; oMessage.Body = builder.ToMessageBody(); var stream = new MemoryStream(); oMessage.WriteTo(stream); var request = new SendRawEmailRequest { RawMessage = new RawMessage { Data = stream }, Source = "" }; using (var client = new AmazonSimpleEmailServiceClient()) { var response = await client.SendRawEmailAsync(request); } } catch (Exception ex) { throw; } }
public async Task <MessageDispatchResult> SendAsync(IMessage message) { var mailMessage = EmailMessage.CreateFromMessage(message); var credentials = this.GetCredentials(); var client = new AmazonSimpleEmailServiceClient(credentials); var request = new SendRawEmailRequest { RawMessage = new RawMessage { Data = RawMailHelper.ConvertMailMessageToMemoryStream(mailMessage) } }; var response = await client.SendRawEmailAsync(request); if (response.HttpStatusCode == HttpStatusCode.OK && !string.IsNullOrEmpty(response.MessageId)) { return(new MessageDispatchResult { Succeeded = true, MessageId = response.MessageId }); } return(new MessageDispatchResult { Succeeded = false, MessageId = response.MessageId, Errors = $"{response.HttpStatusCode}: {StringifyMetaData(response.ResponseMetadata)}" }); }
public Task SendEmailAttachAsync() { using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var builder = new BodyBuilder() { HtmlBody = htmlBody }; message.From.Add(new MailboxAddress(fromName, from)); message.To.Add(new MailboxAddress(ToName, to)); message.Subject = subject; //I'm using the stream method, but you don't have to. using (FileStream stream = File.Open(@"ExAttachment/LambdaSES_Atach.pdf", FileMode.Open)) builder.Attachments.Add("LambdaSES_Atach.pdf", stream); message.Body = builder.ToMessageBody(); message.WriteTo(messageStream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = messageStream } }; var response = emailService.SendRawEmailAsync(request); return(Task.FromResult(response)); } }
public async Task <EmailResult> SendEmail(EmailOptions options) { // Replace USWest2 with the AWS Region you're using for Amazon SES. // Acceptable values are EUWest1, USEast1, and USWest2. using (var client = new AmazonSimpleEmailServiceClient(Settings.Default.AccessKey.FromBase64(), Settings.Default.SecretKey.FromBase64(), RegionEndpoint.USEast1)) { var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(GetMessageStream(options)) }; try { Console.WriteLine("Sending email using Amazon SES..."); var response = await client.SendRawEmailAsync(sendRequest); return(new EmailResult() { EmailId = response.MessageId, StatusCode = response.HttpStatusCode.ToString() }); } catch (Exception ex) { Console.WriteLine("The email was not sent. " + ex.ToString()); return(new EmailResult() { Error = ex.ToString(), StatusCode = "500" }); } } }
private static bool SendRawEmail(EMAIL_Messages email, string attachPath, out string error) { error = string.Empty; var htmlView = AlternateView.CreateAlternateViewFromString(email.MessageBoby, Encoding.UTF8, "text/html"); var mailMessage = new MailMessage { From = new MailAddress(email.MessageFrom), To = { email.ToEmail }, Subject = email.Subject, AlternateViews = { htmlView } }; if (attachPath.Trim() != "") { if (File.Exists(attachPath)) { var objAttach = new Attachment(attachPath) { ContentType = new ContentType("application/octet-stream") }; var disposition = objAttach.ContentDisposition; disposition.DispositionType = "attachment"; disposition.CreationDate = File.GetCreationTime(attachPath); disposition.ModificationDate = File.GetLastWriteTime(attachPath); disposition.ReadDate = File.GetLastAccessTime(attachPath); mailMessage.Attachments.Add(objAttach); } } var rawMessage = new RawMessage(); using (var memoryStream = ConvertMailMessageToMemoryStream(mailMessage)) { rawMessage.Data = memoryStream; } var request = new SendRawEmailRequest { RawMessage = rawMessage, Destinations = new List <string> { email.ToEmail } , Source = email.MessageFrom }; try { _setSecurityProtocol(); var response = _s3MailClinet.SendRawEmail(request); return(response.HttpStatusCode == HttpStatusCode.OK); } catch (AmazonSimpleEmailServiceException ex) { error = Utils.FormatError(ex); return(false); } }
/// <summary> /// <para>Sends an email message, with header and content specified by the /// client. The <c>SendRawEmail</c> action is useful for sending multipart /// MIME emails, with attachments or inline content.</para> <para>The raw /// text of the message must comply with Internet email standards; /// otherwise, the message cannot be sent. For more information, go to /// the Amazon SES Developer Guide.</para> /// </summary> /// /// <param name="sendRawEmailRequest">Container for the necessary /// parameters to execute the SendRawEmail service method on /// AmazonSimpleEmailService.</param> /// /// <returns>The response from the SendRawEmail service method, as /// returned by AmazonSimpleEmailService.</returns> /// /// <exception cref="MessageRejectedException"/> public SendRawEmailResponse SendRawEmail(SendRawEmailRequest sendRawEmailRequest) { IRequest <SendRawEmailRequest> request = new SendRawEmailRequestMarshaller().Marshall(sendRawEmailRequest); SendRawEmailResponse response = Invoke <SendRawEmailRequest, SendRawEmailResponse> (request, this.signer, SendRawEmailResponseUnmarshaller.GetInstance()); return(response); }
/// <summary> /// Envia um email para os destinatarios /// </summary> /// <param name="msg"></param> /// <param name="phone"></param> /// <returns></returns> public static bool SendEmail(string from, string subject, List <string> toList, string body, MemoryStream attachment = null, string fileName = null, string fromDisplayName = null, string contentType = null) { bool sent = false; try { if (string.IsNullOrWhiteSpace(subject) || toList == null || toList.Count > 45 || string.IsNullOrWhiteSpace(body)) { ServiceHelper.ThrowError("INVALID_MESSAGE_PARAMETERS: " + subject + ", " + toList + ", " + (body.Length > 100 ? body.Substring(0, 100) : body)); } MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(from); if (!string.IsNullOrWhiteSpace(fromDisplayName)) { mailMessage.From = new MailAddress(from, fromDisplayName); } else { mailMessage.From = new MailAddress(from); } mailMessage.Subject = subject; mailMessage.SubjectEncoding = Encoding.UTF8; mailMessage.BodyEncoding = Encoding.UTF8; mailMessage.IsBodyHtml = true; AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, Encoding.UTF8, "text/html"); htmlView.ContentType.CharSet = Encoding.UTF8.WebName; mailMessage.AlternateViews.Add(htmlView); //mailMessage.Attachments.Add(new Attachment(attachment,new ContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))); // mailMessage.Attachments.Add(new System.Net.Mail.Attachment(attachment, fileName, MediaTypeNames.Application.Octet)); // mailMessage.Attachments.Add RawMessage rawMessage = new RawMessage(); using (MemoryStream memoryStream = BuildRawMailHelper.ConvertMailMessageToMemoryStream(mailMessage)) { rawMessage.Data = memoryStream; } SendRawEmailRequest request = new SendRawEmailRequest(); request.RawMessage = rawMessage; request.Destinations = toList; request.Source = from; SendRawEmailResponse response = AWSFactory.SESClient.SendRawEmail(request); return(true); } catch (Exception ex) { sent = false; Logger.LogException(ex); } return(sent); }
/// <summary> /// Initiates the asynchronous execution of the SendRawEmail operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SendRawEmail operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <SendRawEmailResponse> SendRawEmailAsync(SendRawEmailRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SendRawEmailRequestMarshaller(); var unmarshaller = SendRawEmailResponseUnmarshaller.Instance; return(InvokeAsync <SendRawEmailRequest, SendRawEmailResponse>(request, marshaller, unmarshaller, cancellationToken)); }
IAsyncResult invokeSendRawEmail(SendRawEmailRequest sendRawEmailRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new SendRawEmailRequestMarshaller().Marshall(sendRawEmailRequest); var unmarshaller = SendRawEmailResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return(result); }
public async Task <Result> SendTemplatedEmailAsync <T>(string toEmail, string toName, string subject, string templateId, T data, IEnumerable <EmailAttachmentDto> attachments, bool isHtml, CancellationToken token) { var msg = new SendRawEmailRequest { Source = $"{_mailerOptions.Sender.Name}<{_mailerOptions.Sender.Email}>", Destinations = new List <string> { $"=?UTF-8?B?{toName.Base64Encode()}?= <{toEmail}>" } }; using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var content = await RazorTemplateEngine.RenderAsync($"~/Templates/{templateId}.cshtml", data); var builder = isHtml ? new BodyBuilder { HtmlBody = content } : new BodyBuilder { TextBody = content }; message.To.Add(new MailboxAddress(toName, toEmail)); message.From.Add(new MailboxAddress(_mailerOptions.Sender.Name, _mailerOptions.Sender.Email)); message.Subject = subject; foreach (var attachment in attachments) { builder.Attachments.Add(attachment.Name, attachment.Content); } message.Body = builder.ToMessageBody(); await message.WriteToAsync(messageStream, token); msg.RawMessage = new RawMessage() { Data = messageStream }; } if (_mailerOptions.SkipSending) { return(Success()); } var response = await _mailer.SendRawEmailAsync(msg, token); if ((int)response.HttpStatusCode >= 400) { return(Failure("Une erreur est survenue pendant l'envoi de l'email avec pièce jointe.", response.ResponseMetadata.Metadata)); } return(Success()); }
public Task SendRawEmail(string htmlBody, string subject, string[] to, string from, bool isHtmlBody, string attachedFileName, string fileContent) { AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, Encoding.UTF8, "text/html"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(from); mailMessage.To.Add(new MailAddress(to.FirstOrDefault())); mailMessage.Subject = subject; mailMessage.SubjectEncoding = Encoding.UTF8; if (htmlBody != null) { mailMessage.AlternateViews.Add(htmlView); } if (attachedFileName.Trim() != "") { string folderName = "Attachment"; string attachPath = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"), folderName); attachPath = (Path.Combine(attachPath, attachedFileName)); if (System.IO.File.Exists(attachPath)) { try { System.Net.Mail.Attachment objAttach = new System.Net.Mail.Attachment(attachPath); objAttach.ContentType = new ContentType(fileContent); System.Net.Mime.ContentDisposition disposition = objAttach.ContentDisposition; disposition.DispositionType = "attachment"; disposition.CreationDate = System.IO.File.GetCreationTime(attachPath); disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachPath); disposition.ReadDate = System.IO.File.GetLastAccessTime(attachPath); mailMessage.Attachments.Add(objAttach); } catch (Exception ex) { } } } RawMessage rawMessage = new RawMessage(ConvertMailMessageToMemoryStream(mailMessage)); SendRawEmailRequest request = new SendRawEmailRequest(rawMessage); Amazon.RegionEndpoint regionEndPoint = Amazon.RegionEndpoint.USWest2; AmazonSimpleEmailServiceConfig config = new AmazonSimpleEmailServiceConfig(); config.RegionEndpoint = regionEndPoint; AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(_mailSettings.AwsAccessKeyId, _mailSettings.AwsSecretAccessKey, config); return(client.SendRawEmailAsync(request)); }
internal SendRawEmailResponse SendRawEmail(SendRawEmailRequest request) { var task = SendRawEmailAsync(request); try { return(task.Result); } catch (AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return(null); } }
private void SendAmazonEmails(string body, string subject, List <string> toAddList, List <string> ccAddList, string attachmentPath, string displayName, string from) { var credentals = new BasicAWSCredentials("AKIAJ3Y6RNHOGDYBN3PA", "YsnHRlKn+RxF4NWwuToiq3SYKxYEoc5w5vR/ebMx"); using (var client = new AmazonSimpleEmailServiceClient(credentals, RegionEndpoint.USWest2)) { RawMessage rmsg = new RawMessage(GetMessageStream(body, subject, toAddList, ccAddList, attachmentPath, displayName, from)); var sendRequest = new SendRawEmailRequest { RawMessage = rmsg }; var response = client.SendRawEmail(sendRequest); Console.WriteLine("AMAZON email was sent successfully."); } }
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 Dispatch(MailMessage mail, IEmailMessage iEmailMessage) { var request = new SendRawEmailRequest { RawMessage = GetMessage(mail, iEmailMessage).ToRawMessage() }; using (var client = new AmazonSimpleEmailServiceClient()) { var response = await client.SendRawEmailAsync(request); if (response.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Failed to send an email: " + response.HttpStatusCode); } } }
public virtual async Task Enviar(string templateId = null) { Message.Subject = Subject; Message.IsBodyHtml = true; Message.Body = Template; using (var stream = ConvertMailMessageToMemoryStream(Message)) using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(ConfigurationManager.AppSettings["awsAccessKeyId"], ConfigurationManager.AppSettings["awsSecretAccessKey"].ToString(), RegionEndpoint.USEast1)) { var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage { Data = stream } }; await client.SendRawEmailAsync(sendRequest); } }
public async Task <bool> SendDistributionListEmail(MimeMessage message) { var stream = new MemoryStream(); message.WriteTo(stream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = stream } }; // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox // 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 West (Oregon) region. Examples of other regions that Amazon SES supports are USEast1 // and EUWest1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.USWest2; var credentials = new BasicAWSCredentials(Config.OutboundEmailServerConfig.AwsAccessKey, Config.OutboundEmailServerConfig.AwsSecretKey); // Instantiate an Amazon SES client, which will make the service call. AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials, REGION); // Send the email. try { //TODO: Might not be right -SJ var result = await client.SendRawEmailAsync(request); if (!String.IsNullOrWhiteSpace(result.MessageId)) { return(true); } return(false); } catch (Exception ex) { var exc = ex.ToString(); } return(false); }
// Based on https://github.com/gianluis90/amazon-send-email/blob/master/SendEmailWithAttachments/Program.cs protected override async Task <string> DoSendAsync(string from, string to, string subject, string bodyText, string bodyHtml, string[] attachments) { logger.Debug($"DoSendAsync():from={from},to={to},subject={subject}"); using (var client = this.GetClient()) using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var builder = new BodyBuilder() { TextBody = bodyText }; if (!string.IsNullOrEmpty(bodyHtml)) { builder.HtmlBody = bodyHtml; } message.From.Add(MailboxAddress.Parse(from)); message.To.Add(MailboxAddress.Parse(to)); message.Subject = subject; if (attachments != null) { foreach (var attachment in attachments) { using (FileStream stream = File.Open(attachment, FileMode.Open)) builder.Attachments.Add(Path.GetFileName(attachment), stream); } } message.Body = builder.ToMessageBody(); message.WriteTo(messageStream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = messageStream } }; var response = await client.SendRawEmailAsync(request); return(response.MessageId); } }
public async Task SendEmailAsync(string to, string attachmentPath) { var fromAddress = System.Environment.GetEnvironmentVariable("FROM_ADDRESS"); if (string.IsNullOrEmpty(fromAddress)) { throw new Exception("Invalid configuration: FROM_ADDRESS environment variable is missing"); } using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.EUWest1)) { using (var messageStream = new MemoryStream()) { var message = new MimeMessage(); var builder = new BodyBuilder() { TextBody = string.Format(textBody, to), HtmlBody = string.Format(htmlBody, to) }; message.From.Add(new MailboxAddress(fromAddress)); message.To.Add(new MailboxAddress(to)); message.Subject = subject; using (FileStream stream = File.Open(attachmentPath, FileMode.Open)) { builder.Attachments.Add(attachmentPath, stream); } message.Body = builder.ToMessageBody(); message.WriteTo(messageStream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = messageStream } }; await client.SendRawEmailAsync(request); } } }
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()); } }
public void SendEmailWithAttachment() { var client = Amazon.AWSClientFactory.CreateAmazonSimpleEmailServiceClient(EmailProcessingConfigurationManager.Section.Amazon.Key, EmailProcessingConfigurationManager.Section.Amazon.Secret); MailMessage m = new MailMessage(); var attachment = new Attachment("TextFile1.txt", "text/plain"); attachment.TransferEncoding = TransferEncoding.QuotedPrintable; m.Attachments.Add(attachment); m.Body = "hello"; m.Subject = "hello"; m.To.Add("*****@*****.**"); m.From = new MailAddress("*****@*****.**"); var messageData = ConvertMailMessageToMemoryStream(m); RawMessage message = new RawMessage(messageData); SendRawEmailRequest request = new SendRawEmailRequest(message); var response = client.SendRawEmail(request); }
public bool SendMailWithAttachments(MemoryStream stream) { using (var client = new AmazonSimpleEmailServiceClient(accesskey, secretkey, RegionEndpoint.EUWest1)) { var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(stream) }; try { var response = client.SendRawEmail(sendRequest); return(true); } catch (Exception e) { return(false); } } }
private async Task <HttpStatusCode> SendEmailAsync(MimeMessage message) { using var memoryStream = new MemoryStream(); await message.WriteToAsync(memoryStream); var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(memoryStream) }; try { var response = await _emailService.SendRawEmailAsync(sendRequest); return(response.HttpStatusCode); } catch { return(HttpStatusCode.BadGateway); } }
public void SendEmails(MemoryStream messageStream) { var credentals = new BasicAWSCredentials("AKIAJKFGC76AKAMIJ7KQ", "7QHGvWfljz8aJ4DWD/LRhq+WxflaShugiEKtZREf"); using (var client = new AmazonSimpleEmailServiceClient(credentals, RegionEndpoint.EUWest1)) { var sendRequest = new SendRawEmailRequest { RawMessage = new RawMessage(messageStream) }; try { var response = client.SendRawEmailAsync(sendRequest); Console.WriteLine("The email was sent successfully."); } catch (Exception e) { Console.WriteLine("The email was not sent."); Console.WriteLine("Error message: " + e.Message); } } }
public void SendDistributionListEmail(MimeMessage message) { var stream = new MemoryStream(); message.WriteTo(stream); var request = new SendRawEmailRequest() { RawMessage = new RawMessage() { Data = stream } }; // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox // 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 West (Oregon) region. Examples of other regions that Amazon SES supports are USEast1 // and EUWest1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.USWest2; var credentials = new BasicAWSCredentials(Config.OutboundEmailServerConfig.AwsAccessKey, Config.OutboundEmailServerConfig.AwsSecretKey); // Instantiate an Amazon SES client, which will make the service call. AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials, REGION); // Send the email. try { //Console.WriteLine("Attempting to send an email through Amazon SES by using the AWS SDK for .NET..."); //client.SendEmail(request); client.SendRawEmail(request); //Console.WriteLine("Email sent!"); } catch (Exception ex) { var exc = ex.ToString(); //Console.WriteLine("The email was not sent."); //Console.WriteLine("Error message: " + ex.Message); } }