Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare GetEmailIdentity con un SDK AWS
Gli esempi di codice seguenti mostrano come utilizzare GetEmailIdentity.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- Python
-
- SDK per Python (Boto3)
-
class SESv2Wrapper:
"""Encapsulates Amazon SESv2 email sending actions."""
def __init__(self, sesv2_client: Any) -> None:
"""
Initializes the SESv2Wrapper with an SESv2 client.
:param sesv2_client: A Boto3 SESv2 client.
"""
self.sesv2_client = sesv2_client
@classmethod
def from_client(cls) -> "SESv2Wrapper":
"""
Creates an SESv2Wrapper instance with a default Boto3 SESv2 client.
:return: A new SESv2Wrapper instance.
"""
sesv2_client = boto3.client("sesv2")
return cls(sesv2_client)
def get_email_identity(self, email_address: str) -> Dict[str, Any]:
"""
Gets information about an email identity, including its verification status.
:param email_address: The email address or domain to look up.
:return: A dictionary with identity information including verification status.
:raises ClientError: If the identity is not found (NotFoundException).
"""
try:
response = self.sesv2_client.get_email_identity(
EmailIdentity=email_address
)
logger.info("Got email identity for %s.", email_address)
return response
except ClientError as err:
if err.response["Error"]["Code"] == "NotFoundException":
logger.info(
"Email identity %s not found.", email_address
)
else:
logger.error(
"Couldn't get email identity %s. Here's why: %s: %s",
email_address,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
- Rust
-
- SDK per Rust
-
Determina se un indirizzo e-mail è stato verificato.
async fn is_verified(client: &Client, email: &str) -> Result<(), Error> {
let resp = client
.get_email_identity()
.email_identity(email)
.send()
.await?;
if resp.verified_for_sending_status() {
println!("The address is verified");
} else {
println!("The address is not verified");
}
Ok(())
}