Amazon SES 示例使用 AWS SDK for .NET - AWS SDK for .NET

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Amazon SES 示例使用 AWS SDK for .NET

下列程式碼範例說明如何透過 AWS SDK for .NET 搭配 Amazon 使用來執行動作和實作常見案例SES。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會顯示如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

例是程式碼範例,向您展示如何透過呼叫服務中的多個函式或與其他函式結合來完成特定工作 AWS 服務。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

動作

下列程式碼範例會示範如何使用CreateTemplate

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考CreateTemplate中的。

下列程式碼範例會示範如何使用DeleteIdentity

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考DeleteIdentity中的。

下列程式碼範例會示範如何使用DeleteTemplate

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考DeleteTemplate中的。

下列程式碼範例會示範如何使用GetIdentityVerificationAttributes

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }

下列程式碼範例會示範如何使用GetSendQuota

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考GetSendQuota中的。

下列程式碼範例會示範如何使用ListIdentities

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考ListIdentities中的。

下列程式碼範例會示範如何使用ListTemplates

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考ListTemplates中的。

下列程式碼範例會示範如何使用SendEmail

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考SendEmail中的。

下列程式碼範例會示範如何使用SendTemplatedEmail

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }

下列程式碼範例會示範如何使用VerifyEmailIdentity

AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <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; }

案例

下列程式碼範例示範如何建立可追蹤 Amazon DynamoDB 表中工作項目的 Web 應用程式,並使用 Amazon 簡單電子郵件服務 (AmazonSES) 傳送報告。

AWS SDK for .NET

示範如何使用 Amazon DynamoDB。 NETAPI以建立可追蹤 DynamoDB 工作資料的動態 Web 應用程式。

有關如何設置和運行的完整源代碼和說明,請參閱中的完整示例GitHub

此範例中使用的服務
  • DynamoDB

  • Amazon SES

下列程式碼範例示範如何建立可追蹤 Amazon Aurora 無伺服器資料庫中工作項目的 Web 應用程式,並使用 Amazon 簡單電子郵件服務 (AmazonSES) 傳送報告。

AWS SDK for .NET

示範如何使用 Amazon 簡單電子郵件服務 (AmazonSES) 建立可追蹤 Amazon Aurora 資料庫中工作項目的 Web 應用程式,以及透過電子郵件傳送報告。 AWS SDK for .NET 這個範例會使用 React.js 建置的前端與RESTful. NET後端。

  • 將 React 網頁應用程式與 AWS 服務整合。

  • 列出、新增、更新和刪除 Aurora 資料表中的項目。

  • 使用 Amazon 傳送篩選工作項目的電子郵件報告SES。

  • 使用隨附的 AWS CloudFormation 指令碼部署和管理範例資源。

有關如何設置和運行的完整源代碼和說明,請參閱中的完整示例GitHub

此範例中使用的服務
  • Aurora

  • Amazon RDS

  • Amazon RDS 數據服務

  • Amazon SES

下列程式碼範例示範如何建立使用 Amazon Rekognition 依照類別偵測影像中物件的應用程式。

AWS SDK for .NET

說明如何使用 Amazon Rekognition。 NETAPI建立一個應用程式,該應用程式使用 Amazon Rekognition 在位於亞馬遜簡單儲存服務 (Amazon S3) 儲存貯體中的映像檔中按類別識別物件。該應用程序向管理員發送電子郵件通知,其中包含使用 Amazon 簡單電子郵件服務(AmazonSES)的結果

有關如何設置和運行的完整源代碼和說明,請參閱中的完整示例GitHub

此範例中使用的服務
  • Amazon Rekognition

  • Amazon S3

  • Amazon SES