ses_send_verification.go - AWS Code Sample


Verifies an SES email address.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "fmt" //go get -u "" "" "" "" ) const ( // Replace with your "From" address. // This address must be verified with Amazon SES. Sender = "" // Replace with a "To" address. If your account // is still in the sandbox, this address must be verified. Recipient = "" ) func main() { // Create a new session in the us-west-2 region. // Replace us-west-2 with the AWS Region you're using for Amazon SES. sess, err := session.NewSession(&aws.Config{ Region:aws.String("us-west-2")}, ) // Create an SES session. svc := ses.New(sess) // Attempt to send the email. _, err = svc.VerifyEmailAddress(&ses.VerifyEmailAddressInput{EmailAddress: aws.String(Recipient)}) // Display error messages if they occur. if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case ses.ErrCodeMessageRejected: fmt.Println(ses.ErrCodeMessageRejected, aerr.Error()) case ses.ErrCodeMailFromDomainNotVerifiedException: fmt.Println(ses.ErrCodeMailFromDomainNotVerifiedException, aerr.Error()) case ses.ErrCodeConfigurationSetDoesNotExistException: fmt.Println(ses.ErrCodeConfigurationSetDoesNotExistException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println("Verification sent to address: " + Recipient) }

Sample Details

Service: ses

Last tested: 2018-03-16

Author: Doug-AWS

Type: full-example