dou7466 2015-10-28 18:34 采纳率: 0%
浏览 49

如何使用Sendgrid的AddSubstitutions方法动态填充电子邮件模板

Using Go, and Sendgrid's API to send emails using Sendgrid email templates. There is a feature Sendgrid added that allows you to dynamically populate strings in the email template. This works. However, I'm trying to use their AddSubstitutions method (Sendgrid's definition of 'AddSubstitutions' below) to pass an array of strings, to be dynamically populated in a Sendgrid email template.

Link to the Sendgrid SMTPAPI Repo: https://github.com/sendgrid/smtpapi-go/blob/master/smtpapi.go

// AddSubstitutions adds a multiple substitutions to a specific key
func (h *SMTPAPIHeader) AddSubstitutions(key string, subs []string) {
    for i := 0; i < len(subs); i++ {
        h.AddSubstitution(key, subs[i])
    }
}

When the API call is made - there are no errors, and an email is sent, however, only the first string in the array that's passed with the 'AddSubstitutions' method populates the email. I've printed the contents of the array to the console, and I can see multiple values exist in the array. In the template, I've tried adding additional '-keys-' to be populated, but when I do that, the first element in the array gets populated multiple times. How can I pass an array to Sendgrid's API, and have it populate the body of the email template with every string in the array? Code below:

 nickNameArray := make([]string, 0)

 for i, _ := range names {
        nickNameArray = append(nickNameArray, names[i])
 }

 m.AddSubstitutions("-nickNames-", nickNameArray)

The message is sent to Sendgrid via another function - this is the relevant logic.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度