Reputation: 170
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. The variable data is the data I pass to 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!
Upvotes: 4
Views: 1935
Reputation: 1181
It's simple, just remove the text
.
As mentioned by a contributor of SendGrid. Read more
Given that dynamic templates contain both HTML and plain text content, text should not be passed when using a dynamic template.
Upvotes: 2
Reputation: 179
It looks like SendGrid uses html
attribute to decide if the content type should be html even though they ignore the content. So, just include that attribute in the payload. Seems weird, but it worked for me.
P.S.: I didn't try it with JavaScript, I'm using Python.
Upvotes: 0