简体   繁体   English

以纯文本形式发送的动态 sendgrid 模板

[英]Dynamic sendgrid templates being sent as plain text

I'm sending email through sendgrid, but when I receive the email, the email is in plain text format, and I would like to send it in html format.我正在通过sendgrid发送电子邮件,但是当我收到电子邮件时,电子邮件是纯文本格式,我想以html格式发送。 The variable data is the data I pass to sgMail.send.变量 data 是我传递给 sgMail.send 的数据。

module.exports = {
data: {
    to: '',
    from: '',
    subject: '',
    text: '',
    templateId: '',
    dynamic_template_data: {
        value_precip: undefined,
        value_humidity: undefined,
        value_windSpeed: undefined,
        value_condition: undefined,
        value_activiti: undefined
    }
},

set: function(to, from, subject, text, templateId, params) {
    this.data.to = to
    this.data.from = from
    this.data.subject = subject
    this.data.text = text
    this.data.templateId = templateId,
    this.data.dynamic_template_data.value_precipitation = params.value_precipitation
    this.data.dynamic_template_data.value_humidity = params.value_humidity
    this.data.dynamic_template_data.value_windSpeed = params.value_windy
    this.data.dynamic_template_data.value_condition = params.value_condition
    this.data.dynamic_template_data.value_activiti = params.value_activiti

},
    send: function() {
    try {
        sgMail.send(this.data)
    } catch (error) {
        console.log(error)
    }

   }
}

I don't know what may be causing this problem, if anyone can help me I would be grateful!我不知道是什么导致了这个问题,如果有人能帮助我,我将不胜感激!

It looks like SendGrid uses html attribute to decide if the content type should be html even though they ignore the content.看起来 SendGrid 使用html属性来决定内容类型是否应该是 html ,即使它们忽略了内容。 So, just include that attribute in the payload.因此,只需在有效负载中包含该属性。 Seems weird, but it worked for me.看起来很奇怪,但它对我有用。

PS: I didn't try it with JavaScript, I'm using Python. PS:我没有用 JavaScript 尝试过,我用的是 Python。

It's simple, just remove the text .很简单,只需删除text

As mentioned by a contributor of SendGrid.正如 SendGrid 的贡献者所提到的。 Read more 阅读更多

Given that dynamic templates contain both HTML and plain text content, text should not be passed when using a dynamic template.鉴于动态模板包含 HTML 和纯文本内容,因此在使用动态模板时不应传递文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM