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

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

透過 Amazon SES使用 傳送電子郵件 AWS SDK

您可以使用 AWS SDK,透過 Amazon 傳送電子郵件SES。 AWS SDKs 提供多種程式設計語言。如需詳細資訊,請參閱 Amazon Web Services 適用工具

必要條件

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

程式碼範例

重要

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

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

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

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

    • Microsoft Visual Studio Community 2017,15.4.0 版。

    • Microsoft 。NET 架構 4.6.1 版。

    • AWSSDK.Core 套件 (3.3.19 版),使用 安裝 NuGet。

    • AWSSDK.SimpleEmail package (3.3.6.1 版),使用 安裝。 NuGet

    開始之前,請執行以下任務:
    使用 傳送電子郵件 AWS SDK for .NET
    1. 執行以下步驟以建立新專案:

      1. 啟動 Visual Studio。

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

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

      4. 在右側的面板中,選擇主控台應用程式 (。NET 架構)

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

    2. 完成下列步驟 NuGet ,使用 將 Amazon SES套件包含在解決方案中:

      1. Solution Explorer 窗格中,用滑鼠右鍵按一下專案,然後選擇管理 NuGet 套件

      2. NuGet: mazonSESSample索引標籤上,選擇瀏覽

      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. 在程式碼編輯器中,執行以下動作:

      • Replace (取代) sender@example.com 使用「從:」電子郵件地址。此地址必須經過驗證。如需詳細資訊,請參閱在 Amazon SES 中驗證身分

      • Replace (取代) recipient@example.com 使用「收件人:」地址。若您的帳戶仍在沙盒中,您也必須驗證此地址。

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

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

      完成時,請儲存 Program.cs

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

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

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

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

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

    Java

    下列程序說明如何使用 Eclipse IDE for Java EE Developers,以及AWS Toolkit for Eclipse建立 AWS SDK專案和修改 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 Simple Email Service 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— 如果您想要SES在美國西部 (奧勒岡) 以外的區域使用 Amazon,請將此區域取代為您要使用的 區域。如需SES可使用 Amazon 的區域清單,請參閱 中的 Amazon Simple Email Service (AmazonSES)AWS 一般參考

    6. 儲存 AmazonSESSample.java

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

      注意

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

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

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

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

    PHP

    本主題說明如何使用 AWS SDK for PHP ,透過 Amazon 傳送電子郵件SES。

    開始之前,請執行以下任務:
    • 安裝 PHP—PHP 可在 https://http://php.net/downloads.php 取得。本教學課程需要 5.5 PHP版或更新版本。安裝 後PHP,請在環境變數PHP中新增路徑至 ,以便您可以從PHP任何命令提示字元執行。本教學課程中的程式碼已使用 7.2.7 PHP 進行測試。

    • 安裝 AWS SDK for PHP 版本 3 — 如需下載和安裝說明,請參閱 AWS SDK for PHP 文件 。本教學課程中的程式碼已使用 3.64.13 版進行測試。 SDK

    SES 使用 ,透過 Amazon 傳送電子郵件 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— 如果您想要SES在美國西部 (奧勒岡) 以外的區域使用 Amazon,請將此區域取代為您要使用的 區域。如需SES可使用 Amazon 的區域清單,請參閱 中的 Amazon Simple Email Service (AmazonSES)AWS 一般參考

    3. 儲存 amazon-ses-sample.php

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

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

      注意

      如果您在執行程式時遇到「cURL 錯誤 60:SSL憑證問題」錯誤,請下載文件 AWS SDK for PHP 中所述的最新 CA 套件。然後,在 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。

    開始之前,請執行以下任務:
    SES 使用 ,透過 Amazon 傳送電子郵件 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— 如果您想要SES在美國西部 (奧勒岡) 以外的區域使用 Amazon,請將此區域取代為您要使用的 區域。如需SES可使用 Amazon 的區域清單,請參閱 中的 Amazon Simple Email Service (AmazonSES)AWS 一般參考

    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 秘密存取金鑰,才能使用 SES 存取 AmazonSDK。您可以使用 AWS Management Console的安全憑證頁面找到您的憑證。如需憑證的詳細資訊,請參閱 Amazon SES 憑證的類型

    • 安裝 Python —Python 可在 https://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) 文件 。本教學課程中的範例程式碼已使用SDK適用於 Python 的 1.4.4 版進行測試。

    SES 使用 SDK for Python 透過 Amazon 傳送電子郵件
    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— 如果您想要SES在美國西部 (奧勒岡) 以外的區域使用 Amazon,請將此區域取代為您要使用的 區域。如需SES可使用 Amazon 的區域清單,請參閱 中的 Amazon Simple Email Service (AmazonSES)AWS 一般參考

    3. 儲存 amazon-ses-sample.py

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

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

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