Amazon SES examples using AWS SDK for .NET - AWS SDK for .NET

Amazon SES examples using AWS SDK for .NET

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for .NET with Amazon SES.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Scenarios are code examples that show you how to accomplish specific tasks by calling multiple functions within a service or combined with other AWS services.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Actions

The following code example shows how to use CreateTemplate.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Create an email template. /// </summary> /// <param name="name">Name of the template.</param> /// <param name="subject">Email subject.</param> /// <param name="text">Email body text.</param> /// <param name="html">Email HTML body text.</param> /// <returns>True if successful.</returns> public async Task<bool> CreateEmailTemplateAsync(string name, string subject, string text, string html) { var success = false; try { var response = await _amazonSimpleEmailService.CreateTemplateAsync( new CreateTemplateRequest { Template = new Template { TemplateName = name, SubjectPart = subject, TextPart = text, HtmlPart = html } }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("CreateEmailTemplateAsync failed with exception: " + ex.Message); } return success; }
  • For API details, see CreateTemplate in AWS SDK for .NET API Reference.

The following code example shows how to use DeleteIdentity.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Delete an email identity. /// </summary> /// <param name="identityEmail">The identity email to delete.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteIdentityAsync(string identityEmail) { var success = false; try { var response = await _amazonSimpleEmailService.DeleteIdentityAsync( new DeleteIdentityRequest { Identity = identityEmail }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("DeleteIdentityAsync failed with exception: " + ex.Message); } return success; }
  • For API details, see DeleteIdentity in AWS SDK for .NET API Reference.

The following code example shows how to use DeleteTemplate.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Delete an email template. /// </summary> /// <param name="templateName">Name of the template.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteEmailTemplateAsync(string templateName) { var success = false; try { var response = await _amazonSimpleEmailService.DeleteTemplateAsync( new DeleteTemplateRequest { TemplateName = templateName }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("DeleteEmailTemplateAsync failed with exception: " + ex.Message); } return success; }
  • For API details, see DeleteTemplate in AWS SDK for .NET API Reference.

The following code example shows how to use GetIdentityVerificationAttributes.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Get identity verification status for an email. /// </summary> /// <returns>The verification status of the email.</returns> public async Task<VerificationStatus> GetIdentityStatusAsync(string email) { var result = VerificationStatus.TemporaryFailure; try { var response = await _amazonSimpleEmailService.GetIdentityVerificationAttributesAsync( new GetIdentityVerificationAttributesRequest { Identities = new List<string> { email } }); if (response.VerificationAttributes.ContainsKey(email)) result = response.VerificationAttributes[email].VerificationStatus; } catch (Exception ex) { Console.WriteLine("GetIdentityStatusAsync failed with exception: " + ex.Message); } return result; }

The following code example shows how to use GetSendQuota.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Get information on the current account's send quota. /// </summary> /// <returns>The send quota response data.</returns> public async Task<GetSendQuotaResponse> GetSendQuotaAsync() { var result = new GetSendQuotaResponse(); try { var response = await _amazonSimpleEmailService.GetSendQuotaAsync( new GetSendQuotaRequest()); result = response; } catch (Exception ex) { Console.WriteLine("GetSendQuotaAsync failed with exception: " + ex.Message); } return result; }
  • For API details, see GetSendQuota in AWS SDK for .NET API Reference.

The following code example shows how to use ListIdentities.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Get the identities of a specified type for the current account. /// </summary> /// <param name="identityType">IdentityType to list.</param> /// <returns>The list of identities.</returns> public async Task<List<string>> ListIdentitiesAsync(IdentityType identityType) { var result = new List<string>(); try { var response = await _amazonSimpleEmailService.ListIdentitiesAsync( new ListIdentitiesRequest { IdentityType = identityType }); result = response.Identities; } catch (Exception ex) { Console.WriteLine("ListIdentitiesAsync failed with exception: " + ex.Message); } return result; }
  • For API details, see ListIdentities in AWS SDK for .NET API Reference.

The following code example shows how to use ListTemplates.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// List email templates for the current account. /// </summary> /// <returns>A list of template metadata.</returns> public async Task<List<TemplateMetadata>> ListEmailTemplatesAsync() { var result = new List<TemplateMetadata>(); try { var response = await _amazonSimpleEmailService.ListTemplatesAsync( new ListTemplatesRequest()); result = response.TemplatesMetadata; } catch (Exception ex) { Console.WriteLine("ListEmailTemplatesAsync failed with exception: " + ex.Message); } return result; }
  • For API details, see ListTemplates in AWS SDK for .NET API Reference.

The following code example shows how to use SendEmail.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Send an email by using Amazon SES. /// </summary> /// <param name="toAddresses">List of recipients.</param> /// <param name="ccAddresses">List of cc recipients.</param> /// <param name="bccAddresses">List of bcc recipients.</param> /// <param name="bodyHtml">Body of the email in HTML.</param> /// <param name="bodyText">Body of the email in plain text.</param> /// <param name="subject">Subject line of the email.</param> /// <param name="senderAddress">From address.</param> /// <returns>The messageId of the email.</returns> public async Task<string> SendEmailAsync(List<string> toAddresses, List<string> ccAddresses, List<string> bccAddresses, string bodyHtml, string bodyText, string subject, string senderAddress) { var messageId = ""; try { var response = await _amazonSimpleEmailService.SendEmailAsync( new SendEmailRequest { Destination = new Destination { BccAddresses = bccAddresses, CcAddresses = ccAddresses, ToAddresses = toAddresses }, Message = new Message { Body = new Body { Html = new Content { Charset = "UTF-8", Data = bodyHtml }, Text = new Content { Charset = "UTF-8", Data = bodyText } }, Subject = new Content { Charset = "UTF-8", Data = subject } }, Source = senderAddress }); messageId = response.MessageId; } catch (Exception ex) { Console.WriteLine("SendEmailAsync failed with exception: " + ex.Message); } return messageId; }
  • For API details, see SendEmail in AWS SDK for .NET API Reference.

The following code example shows how to use SendTemplatedEmail.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Send an email using a template. /// </summary> /// <param name="sender">Address of the sender.</param> /// <param name="recipients">Addresses of the recipients.</param> /// <param name="templateName">Name of the email template.</param> /// <param name="templateDataObject">Data for the email template.</param> /// <returns>The messageId of the email.</returns> public async Task<string> SendTemplateEmailAsync(string sender, List<string> recipients, string templateName, object templateDataObject) { var messageId = ""; try { // Template data should be serialized JSON from either a class or a dynamic object. var templateData = JsonSerializer.Serialize(templateDataObject); var response = await _amazonSimpleEmailService.SendTemplatedEmailAsync( new SendTemplatedEmailRequest { Source = sender, Destination = new Destination { ToAddresses = recipients }, Template = templateName, TemplateData = templateData }); messageId = response.MessageId; } catch (Exception ex) { Console.WriteLine("SendTemplateEmailAsync failed with exception: " + ex.Message); } return messageId; }

The following code example shows how to use VerifyEmailIdentity.

AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Starts verification of an email identity. This request sends an email /// from Amazon SES to the specified email address. To complete /// verification, follow the instructions in the email. /// </summary> /// <param name="recipientEmailAddress">Email address to verify.</param> /// <returns>True if successful.</returns> public async Task<bool> VerifyEmailIdentityAsync(string recipientEmailAddress) { var success = false; try { var response = await _amazonSimpleEmailService.VerifyEmailIdentityAsync( new VerifyEmailIdentityRequest { EmailAddress = recipientEmailAddress }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("VerifyEmailIdentityAsync failed with exception: " + ex.Message); } return success; }

Scenarios

The following code example shows how to create a web application that tracks work items in an Amazon DynamoDB table and uses Amazon Simple Email Service (Amazon SES) to send reports.

AWS SDK for .NET

Shows how to use the Amazon DynamoDB .NET API to create a dynamic web application that tracks DynamoDB work data.

For complete source code and instructions on how to set up and run, see the full example on GitHub.

Services used in this example
  • DynamoDB

  • Amazon SES

The following code example shows how to create a web application that tracks work items in an Amazon Aurora Serverless database and uses Amazon Simple Email Service (Amazon SES) to send reports.

AWS SDK for .NET

Shows how to use the AWS SDK for .NET to create a web application that tracks work items in an Amazon Aurora database and emails reports by using Amazon Simple Email Service (Amazon SES). This example uses a front end built with React.js to interact with a RESTful .NET backend.

  • Integrate a React web application with AWS services.

  • List, add, update, and delete items in an Aurora table.

  • Send an email report of filtered work items using Amazon SES.

  • Deploy and manage example resources with the included AWS CloudFormation script.

For complete source code and instructions on how to set up and run, see the full example on GitHub.

Services used in this example
  • Aurora

  • Amazon RDS

  • Amazon RDS Data Service

  • Amazon SES

The following code example shows how to build an app that uses Amazon Rekognition to detect objects by category in images.

AWS SDK for .NET

Shows how to use Amazon Rekognition .NET API to create an app that uses Amazon Rekognition to identify objects by category in images located in an Amazon Simple Storage Service (Amazon S3) bucket. The app sends the admin an email notification with the results using Amazon Simple Email Service (Amazon SES).

For complete source code and instructions on how to set up and run, see the full example on GitHub.

Services used in this example
  • Amazon Rekognition

  • Amazon S3

  • Amazon SES