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