英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论