2017-06-21 17 views
0

golangで添付ファイル付きのAWS SES SendRawEmailを実装する方法: 私は、golangの添付ファイルで<br> 私は次のコードで試してみましたアマゾンSES SendRawEmailを実装する必要が

session, err := session.NewSession() 
svc := ses.New(session, &aws.Config{Region: aws.String("us-west-2")}) 

source := aws.String("XXX <[email protected]>") 
destinations := []*string{aws.String("xxx <[email protected]>")} 
message := ses.RawMessage{ Data: []byte(` From: xxx <[email protected]>\\nTo: xxx <[email protected]>\\nSubject: Test email (contains an attachment)\\nMIME-Version: 1.0\\nContent-type: Multipart/Mixed; boundary=\"NextPart\"\\n\\n--NextPart\\nContent-Type: text/plain\\n\\nThis is the message body.\\n\\n--NextPart\\nContent-Type: text/plain;\\nContent-Disposition: attachment; filename=\"sample.txt\"\\n\\nThis is the text in the attachment.\\n\\n--NextPart--" `)} 
input := ses.SendRawEmailInput{Source: source, Destinations: destinations, RawMessage: &message} 
output, err := svc.SendRawEmail(&input) 

が、私は受信メールに、それは示してい

添付ファイルの代わりに私がメッセージに与えた内容。正確に何が間違っているか分かりませんか?

答えて

3

AWS example添付ファイル付きRAW電子メールの送信を参照してください。

実装の提案:電子メールを簡単に作成し、バイトとして電子メールを取得し、上記の参考例で説明したようにSESに送信します。

ライブラリgopkg.in/gomail.v2を使用して、添付ファイル付きのメールを作成し、WriteToメソッドに電話してください。

var emailRaw bytes.Buffer 
emailMessage.WriteTo(&emailRaw) 

// while create instance of RawMessage 
RawMessage: &ses.RawMessage{ 
    Data: emailRaw.Bytes(), 
} 

幸運!


EDIT:コメントについては

はメール:

msg := gomail.NewMessage() 
msg.SetHeader("From", "[email protected]") 
msg.SetHeader("To", "[email protected]", "[email protected]") 
msg.SetHeader("Subject", "Hello!") 
msg.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!") 
msg.Attach("/home/Alex/lolcat.jpg") 

var emailRaw bytes.Buffer 
msg.WriteTo(&emailRaw) 

message := ses.RawMessage{ Data: emailRaw.Bytes() } 

// Remaining is same as what you mentioned the question. 
+0

構図をuは私の例を表示することができます... – A4u

+0

'ses.RawMessage.Data'値は、添付ファイル付きの有効なメールではありません。私は電子メールの例で答えを更新しました。 – jeevatkm

+0

'msg.WriteTo(emailRaw)'は 'msg.WriteTo(&emailRaw)'にする必要があります。 – brunetto

関連する問題