Menu
AWS SDK for Go
Developer Guide

Getting Amazon SES Statistics

The following example demonstrates how to use the AWS SDK for Go to get statistics about Amazon SES. Use this information to avoid damaging your reputation when emails are bounced or rejected.

Copy
package main import ( "fmt" //go get -u github.com/aws/aws-sdk-go "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" "github.com/aws/aws-sdk-go/aws/awserr" ) 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. result, err := svc.GetSendStatistics(nil) // 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 } dps := result.SendDataPoints fmt.Println("Got", len(dps), "datapoints") fmt.Println("") for _, dp := range dps { fmt.Println("Timestamp: ", dp.Timestamp) fmt.Println("Attempts: ", aws.Int64Value(dp.DeliveryAttempts)) fmt.Println("Bounces: ", aws.Int64Value(dp.Bounces)) fmt.Println("Complaints:", aws.Int64Value(dp.Complaints)) fmt.Println("Rejects: ", aws.Int64Value(dp.Rejects)) fmt.Println("") } }

See the complete example on GitHub.