AWS SES不使用SendRawEmail操作发送电子邮件。

huangapple go评论80阅读模式
英文:

AWS SES does not send emails using SendRawEmail operation

问题

我在使用AWS golang SDK的SendRawEmail操作发送电子邮件时遇到了问题。尽管我没有收到任何错误,并从AWS收到了MessageId,但我没有收到电子邮件。

使用SendEmail发送电子邮件工作正常,我可以收到电子邮件。

我的代码如下:

  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

我将我的Gmail作为目标电子邮件,不知道这是否有任何影响。

英文:

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.

答案1

得分: 2

RawData中的Data不应该是Base64编码的。正如文档所述

> // 数据会被SDK自动进行Base64编码/解码。

英文:

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

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

huangapple
  • 本文由 发表于 2017年3月11日 22:02:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/42736128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定