Search code examples
amazon-web-servicesgoamazon-ses

How to integrate aws sdk ses in golang?


I'm using AWS to host my server in Go language. I am stuck as I'm not sure how to use their AWS SES SDK to send an email. Any ideas?


Solution

  • It is pretty straightforward as shown in the link from your question.

    What are you having trouble with ?

    Minimal Example :

    Imports : github.com/aws/aws-sdk-go/aws, github.com/aws/aws-sdk-go/service/ses and github.com/aws/aws-sdk-go/aws/credentials, github.com/aws/aws-sdk-go/aws/session

    awsSession := session.New(&aws.Config{
            Region:      aws.String("aws.region"),
            Credentials: credentials.NewStaticCredentials("aws.accessKeyID", "aws.secretAccessKey" , ""),
        })
    
    sesSession := ses.New(awsSession)
    
    sesEmailInput := &ses.SendEmailInput{
        Destination: &ses.Destination{
            ToAddresses:  []*string{aws.String("receiver@xyz.com")},
        },
        Message: &ses.Message{
            Body: &ses.Body{
                Html: &ses.Content{
                    Data: aws.String("Body HTML")},
            },
            Subject: &ses.Content{
                Data: aws.String("Subject"),
            },
        },
        Source: aws.String("sender@xyz.com"),
        ReplyToAddresses: []*string{
            aws.String("sender@xyz.com"),
        },
    }
    
    _, err := sesSession.SendEmail(sesEmailInput)