AWS SES 不使用 SendRawEmail 操作发送电子邮件
AWS SES does not send emails using SendRawEmail operation
我在使用 SendRawEmail
操作通过 AWS golang sdk 发送电子邮件时遇到问题。即使我没有收到任何错误并从 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 作为目标电子邮件,如果这有什么不同的话。
RawData
中的 Data
不应使用 base64 编码。作为 documentation states:
// Data is automatically base64 encoded/decoded by the SDK.
我在使用 SendRawEmail
操作通过 AWS golang sdk 发送电子邮件时遇到问题。即使我没有收到任何错误并从 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 作为目标电子邮件,如果这有什么不同的话。
RawData
中的 Data
不应使用 base64 编码。作为 documentation states:
// Data is automatically base64 encoded/decoded by the SDK.