Maksim Sorokin
Maksim Sorokin

Reputation: 2404

AWS SES does not send emails using SendRawEmail operation

I have troubles sending emails with AWS golang sdk using SendRawEmail operation. Even though I get no errors and receive MessageId back from AWS, I do not receive the email.

Sending emails using SendEmail works fine and I receive the email.

My code:

  session, err := session.NewSession()
  if err != nil {
    return err
  }

  svc := ses.New(session, &aws.Config{Region: aws.String("eu-west-1")})

  messageContent := `From: "Alice" <xxx@xxx>
To: "Bob" <xxx@xxx>
Return-Path: <xxx@xxx>
Subject: Hello
Content-Language: en-US
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0

This is a test email`

  base64messageContent := base64.StdEncoding.EncodeToString([]byte(messageContent))

  source := aws.String("xxx@xxx")
  destinations := []*string{aws.String("xxx@xxx")}
  message := ses.RawMessage{Data: []byte(base64messageContent)}

  input := ses.SendRawEmailInput{Source: source, Destinations: destinations, RawMessage: &message}

  output, err := svc.SendRawEmail(&input)

  if err != nil {
    return err
  }

  log.Println("Response from SES", output)

  return nil
}

I am using my Gmail as the destination email, if that makes any difference.

Upvotes: 1

Views: 1679

Answers (1)

Maksim Sorokin
Maksim Sorokin

Reputation: 2404

Data in RawData should not be base64 encoded. As documentation states:

// Data is automatically base64 encoded/decoded by the SDK.

Upvotes: 2

Related Questions