SESEsempi di utilizzo di Amazon AWS SDK for .NET - Esempi di codice dell'AWS SDK

Ci sono altri AWS SDK esempi disponibili 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à.

SESEsempi di utilizzo di Amazon AWS SDK for .NET

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando il AWS SDK for .NET con AmazonSES.

Le operazioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati e negli esempi tra servizi.

Scenari: esempi di codice che mostrano come eseguire un'attività specifica richiamando più funzioni all'interno dello stesso servizio.

Ogni esempio include un collegamento a GitHub, dove puoi trovare istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Azioni

Il seguente esempio di codice mostra come utilizzareCreateTemplate.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Create an email template. /// </summary> /// <param name="name">Name of the template.</param> /// <param name="subject">Email subject.</param> /// <param name="text">Email body text.</param> /// <param name="html">Email HTML body text.</param> /// <returns>True if successful.</returns> public async Task<bool> CreateEmailTemplateAsync(string name, string subject, string text, string html) { var success = false; try { var response = await _amazonSimpleEmailService.CreateTemplateAsync( new CreateTemplateRequest { Template = new Template { TemplateName = name, SubjectPart = subject, TextPart = text, HtmlPart = html } }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("CreateEmailTemplateAsync failed with exception: " + ex.Message); } return success; }

Il seguente esempio di codice mostra come utilizzareDeleteIdentity.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Delete an email identity. /// </summary> /// <param name="identityEmail">The identity email to delete.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteIdentityAsync(string identityEmail) { var success = false; try { var response = await _amazonSimpleEmailService.DeleteIdentityAsync( new DeleteIdentityRequest { Identity = identityEmail }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("DeleteIdentityAsync failed with exception: " + ex.Message); } return success; }

Il seguente esempio di codice mostra come utilizzareDeleteTemplate.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Delete an email template. /// </summary> /// <param name="templateName">Name of the template.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteEmailTemplateAsync(string templateName) { var success = false; try { var response = await _amazonSimpleEmailService.DeleteTemplateAsync( new DeleteTemplateRequest { TemplateName = templateName }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("DeleteEmailTemplateAsync failed with exception: " + ex.Message); } return success; }

Il seguente esempio di codice mostra come utilizzareGetIdentityVerificationAttributes.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Get identity verification status for an email. /// </summary> /// <returns>The verification status of the email.</returns> public async Task<VerificationStatus> GetIdentityStatusAsync(string email) { var result = VerificationStatus.TemporaryFailure; try { var response = await _amazonSimpleEmailService.GetIdentityVerificationAttributesAsync( new GetIdentityVerificationAttributesRequest { Identities = new List<string> { email } }); if (response.VerificationAttributes.ContainsKey(email)) result = response.VerificationAttributes[email].VerificationStatus; } catch (Exception ex) { Console.WriteLine("GetIdentityStatusAsync failed with exception: " + ex.Message); } return result; }

Il seguente esempio di codice mostra come utilizzareGetSendQuota.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Get information on the current account's send quota. /// </summary> /// <returns>The send quota response data.</returns> public async Task<GetSendQuotaResponse> GetSendQuotaAsync() { var result = new GetSendQuotaResponse(); try { var response = await _amazonSimpleEmailService.GetSendQuotaAsync( new GetSendQuotaRequest()); result = response; } catch (Exception ex) { Console.WriteLine("GetSendQuotaAsync failed with exception: " + ex.Message); } return result; }

Il seguente esempio di codice mostra come utilizzareListIdentities.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Get the identities of a specified type for the current account. /// </summary> /// <param name="identityType">IdentityType to list.</param> /// <returns>The list of identities.</returns> public async Task<List<string>> ListIdentitiesAsync(IdentityType identityType) { var result = new List<string>(); try { var response = await _amazonSimpleEmailService.ListIdentitiesAsync( new ListIdentitiesRequest { IdentityType = identityType }); result = response.Identities; } catch (Exception ex) { Console.WriteLine("ListIdentitiesAsync failed with exception: " + ex.Message); } return result; }

Il seguente esempio di codice mostra come utilizzareListTemplates.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// List email templates for the current account. /// </summary> /// <returns>A list of template metadata.</returns> public async Task<List<TemplateMetadata>> ListEmailTemplatesAsync() { var result = new List<TemplateMetadata>(); try { var response = await _amazonSimpleEmailService.ListTemplatesAsync( new ListTemplatesRequest()); result = response.TemplatesMetadata; } catch (Exception ex) { Console.WriteLine("ListEmailTemplatesAsync failed with exception: " + ex.Message); } return result; }

Il seguente esempio di codice mostra come utilizzareSendEmail.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Send an email by using Amazon SES. /// </summary> /// <param name="toAddresses">List of recipients.</param> /// <param name="ccAddresses">List of cc recipients.</param> /// <param name="bccAddresses">List of bcc recipients.</param> /// <param name="bodyHtml">Body of the email in HTML.</param> /// <param name="bodyText">Body of the email in plain text.</param> /// <param name="subject">Subject line of the email.</param> /// <param name="senderAddress">From address.</param> /// <returns>The messageId of the email.</returns> public async Task<string> SendEmailAsync(List<string> toAddresses, List<string> ccAddresses, List<string> bccAddresses, string bodyHtml, string bodyText, string subject, string senderAddress) { var messageId = ""; try { var response = await _amazonSimpleEmailService.SendEmailAsync( new SendEmailRequest { Destination = new Destination { BccAddresses = bccAddresses, CcAddresses = ccAddresses, ToAddresses = toAddresses }, Message = new Message { Body = new Body { Html = new Content { Charset = "UTF-8", Data = bodyHtml }, Text = new Content { Charset = "UTF-8", Data = bodyText } }, Subject = new Content { Charset = "UTF-8", Data = subject } }, Source = senderAddress }); messageId = response.MessageId; } catch (Exception ex) { Console.WriteLine("SendEmailAsync failed with exception: " + ex.Message); } return messageId; }

Il seguente esempio di codice mostra come utilizzareSendTemplatedEmail.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Send an email using a template. /// </summary> /// <param name="sender">Address of the sender.</param> /// <param name="recipients">Addresses of the recipients.</param> /// <param name="templateName">Name of the email template.</param> /// <param name="templateDataObject">Data for the email template.</param> /// <returns>The messageId of the email.</returns> public async Task<string> SendTemplateEmailAsync(string sender, List<string> recipients, string templateName, object templateDataObject) { var messageId = ""; try { // Template data should be serialized JSON from either a class or a dynamic object. var templateData = JsonSerializer.Serialize(templateDataObject); var response = await _amazonSimpleEmailService.SendTemplatedEmailAsync( new SendTemplatedEmailRequest { Source = sender, Destination = new Destination { ToAddresses = recipients }, Template = templateName, TemplateData = templateData }); messageId = response.MessageId; } catch (Exception ex) { Console.WriteLine("SendTemplateEmailAsync failed with exception: " + ex.Message); } return messageId; }

Il seguente esempio di codice mostra come utilizzareVerifyEmailIdentity.

AWS SDK for .NET
Nota

C'è altro da fare GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Starts verification of an email identity. This request sends an email /// from Amazon SES to the specified email address. To complete /// verification, follow the instructions in the email. /// </summary> /// <param name="recipientEmailAddress">Email address to verify.</param> /// <returns>True if successful.</returns> public async Task<bool> VerifyEmailIdentityAsync(string recipientEmailAddress) { var success = false; try { var response = await _amazonSimpleEmailService.VerifyEmailIdentityAsync( new VerifyEmailIdentityRequest { EmailAddress = recipientEmailAddress }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("VerifyEmailIdentityAsync failed with exception: " + ex.Message); } return success; }