AWS 文档 SDK 示例
使用适用于 .NET 的 SDK的 Amazon SES 示例
以下代码示例演示如何通过将 适用于 .NET 的 AWS SDK与 Amazon SES 结合使用,来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
场景是向您演示如何通过在一个服务中调用多个函数或与其他 AWS 服务 结合来完成特定任务的代码示例。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
操作
以下代码示例演示如何使用 CreateTemplate。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 CreateTemplate。
-
以下代码示例演示如何使用 DeleteIdentity。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 DeleteIdentity。
-
以下代码示例演示如何使用 DeleteTemplate。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 DeleteTemplate。
-
以下代码示例演示如何使用 GetIdentityVerificationAttributes。
- 适用于 .NET 的 SDK
-
注意
查看 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; }-
有关 API 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 GetIdentityVerificationAttributes。
-
以下代码示例演示如何使用 GetSendQuota。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 GetSendQuota。
-
以下代码示例演示如何使用 ListIdentities。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 ListIdentities。
-
以下代码示例演示如何使用 ListTemplates。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 ListTemplates。
-
以下代码示例演示如何使用 SendEmail。
- 适用于 .NET 的 SDK
-
注意
查看 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 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 SendEmail。
-
以下代码示例演示如何使用 SendTemplatedEmail。
- 适用于 .NET 的 SDK
-
注意
查看 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; }-
有关 API 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 SendTemplatedEmail。
-
以下代码示例演示如何使用 VerifyEmailIdentity。
- 适用于 .NET 的 SDK
-
注意
查看 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; }-
有关 API 详细信息,请参阅《适用于 .NET 的 AWS SDK API 参考》中的 VerifyEmailIdentity。
-
场景
以下代码示例演示如何创建一个 Web 应用程序,来跟踪 Amazon DynamoDB 表中的工作项,并使用 Amazon Simple Email Service(Amazon SES)来发送报告。
- 适用于 .NET 的 SDK
-
展示如何使用 Amazon DynamoDB .NET API 创建用于跟踪 DynamoDB 工作数据的动态 Web 应用程序。
有关完整的源代码以及如何设置和运行的说明,请参阅 GitHub
上的完整示例。 本示例中使用的服务
DynamoDB
Amazon SES
以下代码示例演示如何创建 Web 应用程序,来跟踪 Amazon Aurora Serverless 数据库中的工作项,以及使用 Amazon Simple Email Service(Amazon SES)发送报告。
- 适用于 .NET 的 SDK
-
展示如何使用 适用于 .NET 的 AWS SDK 通过 Amazon Simple Email Service (Amazon SES) 创建 Web 应用程序来跟踪 Amazon Aurora 数据库中的工作项和电子邮件报告。此示例使用由 React.js 构建的前端与 RESTful .NET 后端进行交互。
将 React Web 应用程序与 AWS 服务集成。
列出、添加、更新和删除 Aurora 表中的项目。
使用 Amazon SES 以电子邮件形式发送已筛选工作项的报告。
使用随附的 AWS CloudFormation 脚本部署与管理示例资源。
有关完整的源代码以及如何设置和运行的说明,请参阅 GitHub
上的完整示例。 本示例中使用的服务
Aurora
Amazon RDS
Amazon RDS 数据服务
Amazon SES
以下代码示例演示如何构建采用 Amazon Rekognition 来按类别检测图像中物体的应用程序。
- 适用于 .NET 的 SDK
-
展示如何使用 Amazon Rekognition .NET API 创建应用程序,该应用程序采用 Amazon Rekognition 来按类别识别位于 Amazon Simple Storage Service (Amazon S3) 存储桶的图像中的对象。该应用程序使用 Amazon Simple Email Service (Amazon SES) 向管理员发送包含结果的电子邮件通知。
有关完整的源代码以及如何设置和运行的说明,请参阅 GitHub
上的完整示例。 本示例中使用的服务
Amazon Rekognition
Amazon S3
Amazon SES