I'm new to SendGrid and using the SendGrid APIV3 (Go language package) to send an email with multiple attachments, including different file types like CSV, JPG, ZIP, TXT, PNG, and PPT. I need to send these attachments in a specific order, which is the order in which I add them to the message.
for idx, att := range attachments {
attachment := sendgrid.NewAttachment()
encodedFile := base64.StdEncoding.EncodeToString(att.FileData)
attachment.SetType(att.MIMEType)
attachment.SetFilename(att.FileName)
attachment.SetContent(encodedFile)
message.AddAttachment(attachment)
}
Is there a way to control the order of attachments when sending an email via SendGrid? Does SendGrid follow any default order when attaching files
Any guidance or examples would be appreciated!
I'm new to SendGrid and using the SendGrid APIV3 (Go language package) to send an email with multiple attachments, including different file types like CSV, JPG, ZIP, TXT, PNG, and PPT. I need to send these attachments in a specific order, which is the order in which I add them to the message.
for idx, att := range attachments {
attachment := sendgrid.NewAttachment()
encodedFile := base64.StdEncoding.EncodeToString(att.FileData)
attachment.SetType(att.MIMEType)
attachment.SetFilename(att.FileName)
attachment.SetContent(encodedFile)
message.AddAttachment(attachment)
}
Is there a way to control the order of attachments when sending an email via SendGrid? Does SendGrid follow any default order when attaching files
Any guidance or examples would be appreciated!
Share Improve this question asked Mar 12 at 15:44 ManoMano 111 bronze badge1 Answer
Reset to default 0There is no manner in which SendGrid's API can place attachments in a specific order, and even if it were possible, each email client may still change how those attachments appear to the end user. In other words, even if you could set the order, Gmail may still show them in a different order, and then Microsoft Outlook may show them in a different order yet.
Your best bet is to try to take advantage of the most likely method of sorting attachments that any email client would use; alphanumerically. To that end, I would recommend renaming the files you attach to have a numerical prefix.
1 - mycarets.csv
2 - adobe.pdf
3 - picturethis.png
That will likely get the files in the order you'd prefer the most often.