使用開發 AWS 套件透過 Amazon SES 傳送電子郵件 - Amazon Simple Email Service

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

使用開發 AWS 套件透過 Amazon SES 傳送電子郵件

您可以使用 AWS 開發套件透過 Amazon SES 傳送電子郵件。 AWS SDK 可用於多種編程語言。如需詳細資訊,請參閱 Amazon Web Services 適用工具

必要條件

必須完成下列必要條件,才能完成下一節中的任何程式碼範例:

程式碼範例

重要

在如下教學課程中,可傳送電子郵件給自己,以確認是否成功收到。如需進一步試驗或負載測試,請使用 Amazon SES 信箱模擬器。傳送到信箱模擬器的電子郵件不會計入您的傳送份額或退信率與投訴率。如需詳細資訊,請參閱 手動使用信箱模擬器

選取程式設計語言以檢視該語言的範例:
    .NET

    下列程序說明如何使用 Visual Studio 與 AWS SDK for .NET透過 Amazon SES 傳送電子郵件。

    這個解決方案使用以下元件測試:

    • Microsoft Visual Studio Community 2017,15.4.0 版。

    • Microsoft .NET Framework 版本 4.6.1。

    • AWSSDK.Core 軟件包(版本 3.3.19),使用. NuGet

    • 的 AWSSDK. SimpleEmail 軟件包(版本 3.3.6.1),安裝使用. NuGet

    開始之前,請執行以下任務:
    若要使用 AWS SDK for .NET
    1. 執行以下步驟以建立新專案:

      1. 啟動 Visual Studio。

      2. File (檔案) 選單上,選擇 New (新增)Project (專案)

      3. New Project (新增專案) 視窗上,於左側面板內,展開 Installed (已安裝),然後展開 Visual C#

      4. 在右側的面板上,選擇 Console App (主控台應用程式) (.NET Framework)

      5. 針對 Name (名稱),輸入 AmazonSESSample,然後選擇 OK (確定)

    2. 完成下列步驟,即可在您的解決方案中包含 Amazon SES 套件: NuGet

      1. 在 [方案總管] 窗格中,以滑鼠右鍵按一下專案,然後選擇 [管理 NuGet 套件]。

      2. NuGet:AmazonSESSample 品標籤上,選擇瀏覽

      3. 在搜尋方塊中,輸入 AWSSDK.SimpleEmail

      4. 選擇 AWSSDK. SimpleEmail套件,然後選擇 [安裝]。

      5. Preview Changes (預覽變更) 視窗上,選擇 OK (確定)

    3. Program.cs 標籤上,貼上以下程式碼:

      using Amazon; using System; using System.Collections.Generic; using Amazon.SimpleEmail; using Amazon.SimpleEmail.Model; namespace AmazonSESSample { class Program { // Replace sender@example.com with your "From" address. // This address must be verified with Amazon SES. static readonly string senderAddress = "sender@example.com"; // Replace recipient@example.com with a "To" address. If your account // is still in the sandbox, this address must be verified. static readonly string receiverAddress = "recipient@example.com"; // The configuration set to use for this email. If you do not want to use a // configuration set, comment out the following property and the // ConfigurationSetName = configSet argument below. static readonly string configSet = "ConfigSet"; // The subject line for the email. static readonly string subject = "Amazon SES test (AWS SDK for .NET)"; // The email body for recipients with non-HTML email clients. static readonly string textBody = "Amazon SES Test (.NET)\r\n" + "This email was sent through Amazon SES " + "using the AWS SDK for .NET."; // The HTML body of the email. static readonly string htmlBody = @"<html> <head></head> <body> <h1>Amazon SES Test (AWS SDK for .NET)</h1> <p>This email was sent with <a href='https://aws.amazon.com/ses/'>Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-net/'> AWS SDK for .NET</a>.</p> </body> </html>"; static void Main(string[] args) { // Replace USWest2 with the AWS Region you're using for Amazon SES. // Acceptable values are EUWest1, USEast1, and USWest2. using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2)) { var sendRequest = new SendEmailRequest { Source = senderAddress, Destination = new Destination { ToAddresses = new List<string> { receiverAddress } }, Message = new Message { Subject = new Content(subject), Body = new Body { Html = new Content { Charset = "UTF-8", Data = htmlBody }, Text = new Content { Charset = "UTF-8", Data = textBody } } }, // If you are not using a configuration set, comment // or remove the following line ConfigurationSetName = configSet }; try { Console.WriteLine("Sending email using Amazon 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(); } } }
    4. 在程式碼編輯器中,執行以下動作:

      • 以您的「寄件人」電子郵件地址取代 sender@example.com。此地址必須經過驗證。如需詳細資訊,請參閱「在 Amazon SES 中驗證身分」。

      • 以 "To:" 地址取代 recipient@example.com。若您的帳戶仍在沙盒中,您也必須驗證此地址。

      • 以傳送此電子郵件時要使用的組態集名稱取ConfigSet代。

      • UsWest2 取代為您使用 Amazon SES 傳送電子郵件時使用的 AWS 區域 端點名稱。如需可使用 Amazon SES 的區域清單,請參閱 AWS 一般參考 中的 Amazon Simple Email Service (Amazon SES)

      完成時,請儲存 Program.cs

    5. 完成以下步驟以建置並執行應用程式:

      1. Build (建置) 選單上,選擇 Build Solution (建置解決方案)

      2. Debug (偵錯) 選單上,選擇 Start Debugging (開始偵錯)。將顯示主控台視窗。

    6. 檢視主控台輸出。若電子郵件成功傳送,主控台將顯示 "The email was sent successfully."

    7. 如果電子郵件已成功傳送,請登入收件人地址的電子郵件用戶端。可以看到您已傳送的訊息。

    Java

    下列程序示範如何針對 Java EE 開發人員使用 Eclipse IDE,以及如AWS Toolkit for Eclipse何建立開發 AWS 套件專案,並修改 Java 程式碼,以便透過 Amazon SES 傳送電子郵件。

    開始之前,請執行以下任務:
    • 安裝 Eclipse - Eclipse 可在 https://www.eclipse.org/downloads 下載。此教學中的程式碼使用 Eclipse Neon.3 (版本 4.6.3) 及 Java Runtime Environment 執行版本 1.8 來完成測試。

    • 安裝 AWS Toolkit for Eclipse — 有關添加 AWS Toolkit for Eclipse 到您的 Eclipse 安裝的說明,請訪問 https://aws.amazon.com/eclipse。此教學中的程式碼使用 AWS Toolkit for Eclipse版本 2.3.1 完成測試。

    若要使用 AWS SDK for Java
    1. 通過執行以下步驟在 Eclipse 中創建一個 AWS Java 項目:

      1. 啟動 Eclipse。

      2. File (檔案) 選單上,選擇 New (新增),再選擇 Other (其他)。在 New (新增) 視窗上,展開 AWS 資料夾,然後選擇 AWS Java Project (AWS Java 專案)

      3. 在 [新增 AWS Java 專案] 對話方塊中,執行下列動作:

        1. 針對 Project name (專案名稱),輸入專案的名稱。

        2. AWS SDK for Java 範例下,選取 Amazon 簡易電子郵件服務 JavaMail 範例

        3. 選擇 Finish (完成)。

    2. 在 Eclipse 的 Package Explorer (套件瀏覽器) 窗格中,展開您的專案。

    3. 在您的專案下,展開 src/main/java 資料夾、展開 com.amazon.aws.samples 資料夾,然後按兩下 AmazonSESSample.java

    4. 以下列程式碼取代 AmazonSESSample.java 所有內容:

      package com.amazonaws.samples; import java.io.IOException; import com.amazonaws.regions.Regions; import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder; import com.amazonaws.services.simpleemail.model.Body; import com.amazonaws.services.simpleemail.model.Content; import com.amazonaws.services.simpleemail.model.Destination; import com.amazonaws.services.simpleemail.model.Message; import com.amazonaws.services.simpleemail.model.SendEmailRequest; public class AmazonSESSample { // Replace sender@example.com with your "From" address. // This address must be verified with Amazon SES. static final String FROM = "sender@example.com"; // Replace recipient@example.com with a "To" address. If your account // is still in the sandbox, this address must be verified. static final String TO = "recipient@example.com"; // The configuration set to use for this email. If you do not want to use a // configuration set, comment the following variable and the // .withConfigurationSetName(CONFIGSET); argument below. static final String CONFIGSET = "ConfigSet"; // The subject line for the email. static final String SUBJECT = "Amazon SES test (AWS SDK for Java)"; // The HTML body for the email. static final String HTMLBODY = "<h1>Amazon SES test (AWS SDK for Java)</h1>" + "<p>This email was sent with <a href='https://aws.amazon.com/ses/'>" + "Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-java/'>" + "AWS SDK for Java</a>"; // The email body for recipients with non-HTML email clients. static final String TEXTBODY = "This email was sent through Amazon SES " + "using the AWS SDK for Java."; public static void main(String[] args) throws IOException { try { AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard() // Replace US_WEST_2 with the AWS Region you're using for // Amazon SES. .withRegion(Regions.US_WEST_2).build(); SendEmailRequest request = new SendEmailRequest() .withDestination( new Destination().withToAddresses(TO)) .withMessage(new Message() .withBody(new Body() .withHtml(new Content() .withCharset("UTF-8").withData(HTMLBODY)) .withText(new Content() .withCharset("UTF-8").withData(TEXTBODY))) .withSubject(new Content() .withCharset("UTF-8").withData(SUBJECT))) .withSource(FROM) // Comment or remove the next line if you are not using a // configuration set .withConfigurationSetName(CONFIGSET); client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent. Error message: " + ex.getMessage()); } } }
    5. AmazonSESSample.java 中,以自訂值取代下列項目:

      重要

      電子郵件地址會區分大小寫。請確認此地址與您已完成驗證的地址完全相同。

      • SENDER@EXAMPLE.COM - 以您的「寄件者」電子郵件地址取代。執行此程式前,須先驗證此地址。如需詳細資訊,請參閱 在 Amazon SES 中驗證身分

      • RECIPIENT@EXAMPLE.COM - 以您的「收件人」電子郵件地址取代。如果您的帳戶仍在沙盒中,您必須在使用前先驗證這個地址。如需詳細資訊,請參閱「申請生產存取權 (移出 Amazon SES 沙箱)」。

      • (選用)us-west-2 - 若您想要在美國西部 (奧勒岡) 以外的區域中使用 Amazon SES,請在您想要使用的區域中以此區域取代。如需可使用 Amazon SES 的區域清單,請參閱 AWS 一般參考 中的 Amazon Simple Email Service (Amazon SES)

    6. 儲存 AmazonSESSample.java

    7. 若要建置專案,請選擇 Project (專案),然後選擇 Build Project (建置專案)

      注意

      如果此選項為停用,自動建立可能已啟用;若有此情況則可略過這個步驟。

    8. 若要啟動程式並傳送電子郵件,請選擇 Run (執行),然後再次選擇 Run (執行)

    9. 檢閱 Eclipse 中的主控台窗格輸出。若電子郵件成功傳送,主控台會顯示 "Email sent!" 否則,它會顯示錯誤訊息。

    10. 如果電子郵件已成功傳送,請登入收件人地址的電子郵件用戶端。可以看到您已傳送的訊息。

    PHP

    此主題示範如何使用 AWS SDK for PHP 來透過 Amazon SES 傳送電子郵件。

    開始之前,請執行以下任務:
    • 安裝 PHP - PHP 可在 http://php.net/downloads.php 取得。此教學需要 PHP 版本 5.5 或更新版本。安裝 PHP 後,在環境變數中將路徑新增至 PHP,即可透過任何命令提示來執行 PHP。本教學中使用的程式碼使用 PHP 7.2.7 測試。

    • 安裝 AWS SDK for PHP 版本 3 — 如需下載和安裝指示,請參閱AWS SDK for PHP 文件。本教學中的程式碼使用版本 3.64.13 的軟體開發套件完成測試。

    若要透過 Amazon SES 傳送電子郵件,請使用 AWS SDK for PHP
    1. 在文字編輯器中,建立名為 amazon-ses-sample.php 的檔案。貼上以下程式碼:

      <?php // If necessary, modify the path in the require statement below to refer to the // location of your Composer autoload.php file. require 'vendor/autoload.php'; use Aws\Ses\SesClient; use Aws\Exception\AwsException; // Create an SesClient. Change the value of the region parameter if you're // using an AWS Region other than US West (Oregon). Change the value of the // profile parameter if you want to use a profile in your credentials file // other than the default. $SesClient = new SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-west-2' ]); // Replace sender@example.com with your "From" address. // This address must be verified with Amazon SES. $sender_email = 'sender@example.com'; // Replace these sample addresses with the addresses of your recipients. If // your account is still in the sandbox, these addresses must be verified. $recipient_emails = ['recipient1@example.com','recipient2@example.com']; // Specify a configuration set. If you do not want to use a configuration // set, comment the following variable, and the // 'ConfigurationSetName' => $configuration_set argument below. $configuration_set = 'ConfigSet'; $subject = 'Amazon SES test (AWS SDK for PHP)'; $plaintext_body = 'This email was sent with Amazon SES using the AWS SDK for PHP.' ; $html_body = '<h1>AWS Amazon Simple Email Service Test Email</h1>'. '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'. 'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'. 'AWS SDK for PHP</a>.</p>'; $char_set = 'UTF-8'; try { $result = $SesClient->sendEmail([ 'Destination' => [ 'ToAddresses' => $recipient_emails, ], 'ReplyToAddresses' => [$sender_email], 'Source' => $sender_email, 'Message' => [ 'Body' => [ 'Html' => [ 'Charset' => $char_set, 'Data' => $html_body, ], 'Text' => [ 'Charset' => $char_set, 'Data' => $plaintext_body, ], ], 'Subject' => [ 'Charset' => $char_set, 'Data' => $subject, ], ], // If you aren't using a configuration set, comment or delete the // following line 'ConfigurationSetName' => $configuration_set, ]); $messageId = $result['MessageId']; echo("Email sent! Message ID: $messageId"."\n"); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n"); echo "\n"; }
    2. amazon-ses-sample.php 中,以自訂值取代下列項目:

      • path_to_sdk_inclusion取代為包含在程式中所需 AWS SDK for PHP 的路徑。如需詳細資訊,請參閱 AWS SDK for PHP 文件

      • sender@example.com - 以您已透過 Amazon SES 驗證的電子郵件地址來取代。如需詳細資訊,請參閱 驗證身分。Amazon SES 中的電子郵件地址會區分大小寫。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • recipient1@example.comrecipient2@example.com—以收件人的地址取代。若您的帳戶仍在沙盒中,您也必須驗證您收件人的地址。如需詳細資訊,請參閱「申請生產存取權 (移出 Amazon SES 沙箱)」。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • (選用)ConfigSet - 若您希望在傳送此電子郵件時使用組態集,請用組態集的名稱取代此值。如需組態集的詳細資訊,請參閱 使用 Amazon SES 中的組態集

      • (選用)us-west-2 - 若您想要在美國西部 (奧勒岡) 以外的區域中使用 Amazon SES,請在您想要使用的區域中以此區域取代。如需可使用 Amazon SES 的區域清單,請參閱 AWS 一般參考 中的 Amazon Simple Email Service (Amazon SES)

    3. 儲存 amazon-ses-sample.php

    4. 若要執行程式,請在與 amazon-ses-sample.php 相同的目錄中開啟命令提示,然後輸入以下命令:

      $ php amazon-ses-sample.php
    5. 檢閱輸出。若電子郵件成功傳送,主控台會顯示 "Email sent!" 否則,它會顯示錯誤訊息。

      注意

      若在執行程式時發生 "cURL error 60: SSL certificate problem" (cURL 錯誤 60:SSL 憑證問題) 錯誤,請下載最新的 CA bundle,如 AWS SDK for PHP 文件中所述。然後,在 amazon-ses-sample.php 中,新增下列幾行到 SesClient::factory 陣列,以前往 CA bundle 的下載路徑取代 path_of_certs,然後重新執行程式。

      'http' => [ 'verify' => 'path_of_certs\ca-bundle.crt' ]
    6. 登入收件人地址的電子郵件用戶端。可以看到您已傳送的訊息。

    Ruby

    此主題示範如何使用 AWS SDK for Ruby 來透過 Amazon SES 傳送電子郵件。

    開始之前,請執行以下任務:
    若要透過 Amazon SES 傳送電子郵件,請使用 AWS SDK for Ruby
    1. 在文字編輯器中,建立名為 amazon-ses-sample.rb 的檔案。將以下程式碼貼到檔案:

      require 'aws-sdk' # Replace sender@example.com with your "From" address. # This address must be verified with Amazon SES. sender = "sender@example.com" # Replace recipient@example.com with a "To" address. If your account # is still in the sandbox, this address must be verified. recipient = "recipient@example.com" # Specify a configuration set. If you do not want to use a configuration # set, comment the following variable and the # configuration_set_name: configsetname argument below. configsetname = "ConfigSet" # Replace us-west-2 with the AWS Region you're using for Amazon SES. awsregion = "us-west-2" # The subject line for the email. subject = "Amazon SES test (AWS SDK for Ruby)" # The HTML body of the email. htmlbody = '<h1>Amazon SES test (AWS SDK for Ruby)</h1>'\ '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'\ 'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-ruby/">'\ 'AWS SDK for Ruby</a>.' # The email body for recipients with non-HTML email clients. textbody = "This email was sent with Amazon SES using the AWS SDK for Ruby." # Specify the text encoding scheme. encoding = "UTF-8" # Create a new SES resource and specify a region ses = Aws::SES::Client.new(region: awsregion) # Try to send the email. begin # Provide the contents of the email. resp = ses.send_email({ destination: { to_addresses: [ recipient, ], }, message: { body: { html: { charset: encoding, data: htmlbody, }, text: { charset: encoding, data: textbody, }, }, subject: { charset: encoding, data: subject, }, }, source: sender, # Comment or remove the following line if you are not using # a configuration set configuration_set_name: configsetname, }) puts "Email sent!" # If something goes wrong, display an error message. rescue Aws::SES::Errors::ServiceError => error puts "Email not sent. Error message: #{error}" end
    2. amazon-ses-sample.rb 中,以自訂值取代下列項目:

      • sender@example.com - 以您已透過 Amazon SES 驗證的電子郵件地址來取代。如需詳細資訊,請參閱 驗證身分。Amazon SES 中的電子郵件地址會區分大小寫。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • recipient@example.com - 以收件人的地址取代。如果您的帳戶仍在沙盒中,您必須在使用前先驗證這個地址。如需詳細資訊,請參閱 申請生產存取權 (移出 Amazon SES 沙箱)。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • (選用)us-west-2 - 若您想要在美國西部 (奧勒岡) 以外的區域中使用 Amazon SES,請在您想要使用的區域中以此區域取代。如需可使用 Amazon SES 的區域清單,請參閱 AWS 一般參考 中的 Amazon Simple Email Service (Amazon SES)

    3. 儲存 amazon-ses-sample.rb

    4. 若要執行程式,請在與 amazon-ses-sample.rb 相同的目錄中開啟命令提示,然後輸入 ruby amazon-ses-sample.rb

    5. 檢閱輸出。若電子郵件成功傳送,主控台會顯示 "Email sent!" 否則,它會顯示錯誤訊息。

    6. 登入收件人地址的電子郵件用戶端。可以找到您已傳送的訊息。

    Python

    此主題示範如何使用 AWS SDK for Python (Boto) 來透過 Amazon SES 傳送電子郵件。

    開始之前,請執行以下任務:
    • 以 Amazon SES 驗證您的電子郵件地址 - 您必須先驗證您為寄件者電子郵件地址的擁有者,才可以使用 Amazon SES 傳送電子郵件。如果您的帳戶仍在 Amazon SES 沙盒中,您必須同時驗證收件人地址。建議您使用 Amazon SES 主控台來驗證電子郵件地址。如需詳細資訊,請參閱 建立電子郵件地址身分

    • 得您的 AWS 登入資料 — 您需要 AWS 存取金鑰 ID 和 AWS 秘密存取金鑰,才能使用開發套件存取 Amazon SES。您可以使用 AWS Management Console的安全憑證頁面找到您的憑證。如需憑證的詳細資訊,請參閱 Amazon SES 憑證的類型

    • 安裝 Python - Python 可在 https://www.python.org/downloads/ 下載。本教學中的程式碼已使用 Python 2.7.6 版及 Python 3.6.1 版測試。在您安裝 Python 後,請在環境變數中新增指向 Python 的路徑,讓您可以從任何命令提示執行 Python。

    • 安裝 AWS SDK for Python (Boto) — 如需下載和安裝指示,請參閱AWS SDK for Python (Boto) 文件。此教學中的範本程式碼使用適用於 Python 的軟體開發套件 1.4.4 版進行測試。

    使用適用於 Python 的軟體開發套件透過 Amazon SES 傳送電子郵件
    1. 在文字編輯器中,建立名為 amazon-ses-sample.py 的檔案。將以下程式碼貼到檔案:

      import boto3 from botocore.exceptions import ClientError # Replace sender@example.com with your "From" address. # This address must be verified with Amazon SES. SENDER = "Sender Name <sender@example.com>" # Replace recipient@example.com with a "To" address. If your account # is still in the sandbox, this address must be verified. RECIPIENT = "recipient@example.com" # Specify a configuration set. If you do not want to use a configuration # set, comment the following variable, and the # ConfigurationSetName=CONFIGURATION_SET argument below. CONFIGURATION_SET = "ConfigSet" # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES. AWS_REGION = "us-west-2" # The subject line for the email. SUBJECT = "Amazon SES Test (SDK for Python)" # The email body for recipients with non-HTML email clients. BODY_TEXT = ("Amazon SES Test (Python)\r\n" "This email was sent with Amazon SES using the " "AWS SDK for Python (Boto)." ) # The HTML body of the email. BODY_HTML = """<html> <head></head> <body> <h1>Amazon SES Test (SDK for Python)</h1> <p>This email was sent with <a href='https://aws.amazon.com/ses/'>Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-python/'> AWS SDK for Python (Boto)</a>.</p> </body> </html> """ # The character encoding for the email. CHARSET = "UTF-8" # Create a new SES resource and specify a region. client = boto3.client('ses',region_name=AWS_REGION) # Try to send the email. try: #Provide the contents of the email. response = client.send_email( Destination={ 'ToAddresses': [ RECIPIENT, ], }, Message={ 'Body': { 'Html': { 'Charset': CHARSET, 'Data': BODY_HTML, }, 'Text': { 'Charset': CHARSET, 'Data': BODY_TEXT, }, }, 'Subject': { 'Charset': CHARSET, 'Data': SUBJECT, }, }, Source=SENDER, # If you are not using a configuration set, comment or delete the # following line ConfigurationSetName=CONFIGURATION_SET, ) # Display an error if something goes wrong. except ClientError as e: print(e.response['Error']['Message']) else: print("Email sent! Message ID:"), print(response['MessageId'])
    2. amazon-ses-sample.py 中,以自訂值取代下列項目:

      • sender@example.com - 以您已透過 Amazon SES 驗證的電子郵件地址來取代。如需詳細資訊,請參閱 驗證身分。Amazon SES 中的電子郵件地址會區分大小寫。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • recipient@example.com - 以收件人的地址取代。如果您的帳戶仍在沙盒中,您必須在使用前先驗證這個地址。如需詳細資訊,請參閱 申請生產存取權 (移出 Amazon SES 沙箱)。請確認您輸入的地址與您已完成驗證的地址完全相同。

      • (選用)us-west-2 - 若您想要在美國西部 (奧勒岡) 以外的區域中使用 Amazon SES,請在您想要使用的區域中以此區域取代。如需可使用 Amazon SES 的區域清單,請參閱 AWS 一般參考 中的 Amazon Simple Email Service (Amazon SES)

    3. 儲存 amazon-ses-sample.py

    4. 若要執行程式,請在與 amazon-ses-sample.py 相同的目錄中開啟命令提示,然後輸入 python amazon-ses-sample.py

    5. 檢閱輸出。若電子郵件成功傳送,主控台會顯示 "Email sent!" 否則,它會顯示錯誤訊息。

    6. 登入收件人地址的電子郵件用戶端。可以看到您已傳送的訊息。