搭ListContacts配使用 AWS SDK或 CLI - Amazon Simple Email Service

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

ListContacts配使用 AWS SDK或 CLI

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

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

/// <summary> /// Lists the contacts in the specified contact list. /// </summary> /// <param name="contactListName">The name of the contact list.</param> /// <returns>The list of contacts response from the ListContacts operation.</returns> public async Task<List<Contact>> ListContactsAsync(string contactListName) { var request = new ListContactsRequest { ContactListName = contactListName }; try { var response = await _sesClient.ListContactsAsync(request); return response.Contacts; } catch (NotFoundException ex) { Console.WriteLine($"The contact list {contactListName} does not exist."); Console.WriteLine(ex.Message); } catch (TooManyRequestsException ex) { Console.WriteLine("Too many requests were made. Please try again later."); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine($"An error occurred while listing the contacts: {ex.Message}"); } return new List<Contact>(); }
  • 有API關詳細資訊,請參閱 ListContactsAWS SDK for .NET API參考

Java
SDK對於爪哇 2.x
注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

ListContactsRequest contactListRequest = ListContactsRequest.builder() .contactListName(CONTACT_LIST_NAME) .build(); List<String> contactEmails; try { ListContactsResponse contactListResponse = sesClient.listContacts(contactListRequest); contactEmails = contactListResponse.contacts().stream() .map(Contact::emailAddress) .toList(); } catch (Exception e) { // TODO: Remove when listContacts's GET body issue is resolved. contactEmails = this.contacts; }
  • 有API關詳細資訊,請參閱 ListContactsAWS SDK for Java 2.x API參考

Python
SDK對於 Python(肉毒桿菌 3)
注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

def main(): """ The main function that orchestrates the execution of the workflow. """ print(INTRO) ses_client = boto3.client("sesv2") workflow = SESv2Workflow(ses_client) try: workflow.prepare_application() workflow.gather_subscriber_email_addresses() workflow.send_coupon_newsletter() workflow.monitor_and_review() except ClientError as e: print_error(e) workflow.clean_up() class SESv2Workflow: """ A class to manage the SES v2 Coupon Newsletter Workflow. """ def __init__(self, ses_client, sleep=True): self.ses_client = ses_client self.sleep = sleep try: contacts_response = self.ses_client.list_contacts( ContactListName=CONTACT_LIST_NAME ) except ClientError as e: if e.response["Error"]["Code"] == "NotFoundException": print(f"Contact list '{CONTACT_LIST_NAME}' does not exist.") return else: raise e
  • 有API關詳細資訊,請參閱 ListContactsAWS SDK對於 Python(肉毒桿 3)API參考。

Rust
SDK對於生鏽
注意

還有更多關於 GitHub。尋找完整範例,並瞭解如何在 AWS 代碼示例存儲庫

async fn show_contacts(client: &Client, list: &str) -> Result<(), Error> { let resp = client .list_contacts() .contact_list_name(list) .send() .await?; println!("Contacts:"); for contact in resp.contacts() { println!(" {}", contact.email_address().unwrap_or_default()); } Ok(()) }
  • 有API關詳細資訊,請參閱 ListContactsAWS SDKAPI供鐵鏽參考

有關的完整列表 AWS SDK開發人員指南和代碼示例,請參閱搭配 AWS 開發套件使用 Amazon SES。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。