Golang gomail send email with PDF as attachment with AWS SES

I am trying to use gomail to send raw message via AWS's SES (Simple Email Service). In the email, I have to attach a PDF file as attachment.

Currently, I am able to receive my email and see the contents and that there's an attached pdf file. However, when I click on it, trying to open, it shows "Something went wrong. Try again later".

source := aws.String(ses_aws.Sender)
destinations := []string{recipent}

msg := gomail.NewMessage()
msg.SetHeader("From", ses_aws.Sender)
msg.SetHeader("To", recipent)
msg.SetHeader("Subject", "XXX")
msg.SetBody("text/html", "XXXX")
msg.Attach("pdf.pdf",
gomail.SetCopyFunc(func(w io.Writer) error {
_, err := w.Write(data)
    return err
    }),
)
var emailRaw bytes.Buffer
msg.WriteTo(&emailRaw)

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

input := &ses.SendRawEmailInput{
        Source: source,
        Destinations: destinations,
        RawMessage:     message,
    }
output, err := svc.SendRawEmail(context.TODO(), input)
    if err != nil {
        return "", err
    }

May I ask what is causing the issue? There is also no error in the logs. Please see my code below. Specifically, do I need to set header for MIME? and Content-type? If so, what is the proper way of doing it? Because when I try to set, it tells me that this header already exist, please help thank you!

Upvotes: 1

Views: 416

Answers (0)

Related Questions