最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

twilio - How to Send Attachments in a Specific Order Using SendGrid API? - Stack Overflow

programmeradmin0浏览0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

There 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.

发布评论

评论列表(0)

  1. 暂无评论