Use CreateEmailIdentity com um AWS SDK ou CLI - Amazon Simple Email Service

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

Use CreateEmailIdentity com um AWS SDK ou CLI

Os exemplos de códigos a seguir mostram como usar CreateEmailIdentity.

Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação no contexto no seguinte exemplo de código:

.NET
AWS SDK for .NET
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

/// <summary> /// Creates an email identity (email address or domain) and starts the verification process. /// </summary> /// <param name="emailIdentity">The email address or domain to create and verify.</param> /// <returns>The response from the CreateEmailIdentity operation.</returns> public async Task<CreateEmailIdentityResponse> CreateEmailIdentityAsync(string emailIdentity) { var request = new CreateEmailIdentityRequest { EmailIdentity = emailIdentity }; try { var response = await _sesClient.CreateEmailIdentityAsync(request); return response; } catch (AlreadyExistsException ex) { Console.WriteLine($"Email identity {emailIdentity} already exists."); Console.WriteLine(ex.Message); throw; } catch (ConcurrentModificationException ex) { Console.WriteLine($"The email identity {emailIdentity} is being modified by another operation or thread."); Console.WriteLine(ex.Message); throw; } catch (LimitExceededException ex) { Console.WriteLine("The limit for email identities has been exceeded."); Console.WriteLine(ex.Message); throw; } catch (NotFoundException ex) { Console.WriteLine($"The email identity {emailIdentity} does not exist."); Console.WriteLine(ex.Message); throw; } catch (TooManyRequestsException ex) { Console.WriteLine("Too many requests were made. Please try again later."); Console.WriteLine(ex.Message); throw; } catch (Exception ex) { Console.WriteLine($"An error occurred while creating the email identity: {ex.Message}"); throw; } }
  • Para obter detalhes da API, consulte CreateEmailIdentitya Referência AWS SDK for .NET da API.

Java
SDK para Java 2.x
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

try { CreateEmailIdentityRequest createEmailIdentityRequest = CreateEmailIdentityRequest.builder() .emailIdentity(verifiedEmail) .build(); sesClient.createEmailIdentity(createEmailIdentityRequest); System.out.println("Email identity created: " + verifiedEmail); } catch (AlreadyExistsException e) { System.out.println("Email identity already exists, skipping creation: " + verifiedEmail); } catch (NotFoundException e) { System.err.println("The provided email address is not verified: " + verifiedEmail); throw e; } catch (LimitExceededException e) { System.err .println("You have reached the limit for email identities. Please remove some identities and try again."); throw e; } catch (SesV2Exception e) { System.err.println("Error creating email identity: " + e.getMessage()); throw e; }
  • Para obter detalhes da API, consulte CreateEmailIdentitya Referência AWS SDK for Java 2.x da API.

Python
SDK para Python (Boto3).
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

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: self.ses_client.create_email_identity(EmailIdentity=self.verified_email) print(f"Email identity '{self.verified_email}' created successfully.") except ClientError as e: # If the email identity already exists, skip and proceed if e.response["Error"]["Code"] == "AlreadyExistsException": print(f"Email identity '{self.verified_email}' already exists.") else: raise e
  • Para obter detalhes da API, consulte a CreateEmailIdentityReferência da API AWS SDK for Python (Boto3).

Rust
SDK para Rust
nota

Tem mais sobre GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

match self .client .create_email_identity() .email_identity(self.verified_email.clone()) .send() .await { Ok(_) => writeln!(self.stdout, "Email identity created successfully.")?, Err(e) => match e.into_service_error() { CreateEmailIdentityError::AlreadyExistsException(_) => { writeln!( self.stdout, "Email identity already exists, skipping creation." )?; } e => return Err(anyhow!("Error creating email identity: {}", e)), }, }
  • Para obter detalhes da API, consulte a CreateEmailIdentityreferência da API AWS SDK for Rust.

Para obter uma lista completa dos guias do desenvolvedor do AWS SDK e exemplos de código, consulteUsando o Amazon SES com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.