[英]Sending html in a email method with meteor
I want to send a email with meteor, that has html table that later I will style. 我想发送一封带有流星的电子邮件,其中包含html表,稍后我将对其进行样式设置。
I have the following code, the email sends fine however, the html is received as a plain text string not as html itself. 我有以下代码,但是电子邮件发送正常,但是html作为纯文本字符串而不是html本身接收。 I am sure there is a simple fix, thanks for help in advanced. 我确信这里有一个简单的修复程序,感谢高级帮助。
client /client/contactSend.js
客户端 /client/contactSend.js
Template.contact.events({
'submit #generalContactForm': function(e) {
e.preventDefault();
fname = $(".fname").val();
$(".hideFormGeneral").css("display","none");
$(".loader").css("display","block");
var data = {
name: "test"
};
var htmlEmail = Blaze.toHTMLWithData(Template.contact_email,data);
Meteor.call('sendEmail','dev@anderskitson.ca','bob@example.com','Hello from Meteor!',htmlEmail);
}
});
`/client/contact_email.html `/client/contact_email.html
<html>
<table width="100%" bgcolor="#fcfcfc" cellpadding="0" cellspacing="0" border="0" id="backgroundTable" st-sortable="postfooter">
<tbody>
<tr>
<td>
<table width="600" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth">
<tbody>
<!-- Spacing -->
<tr>
<td width="100%" height="20"></td>
</tr>
<!-- Spacing -->
<tr>
<td align="center" valign="middle" style="font-family: Helvetica, arial, sans-serif; font-size: 13px;color: #282828" st-content="preheader">
red <a href="#" style="text-decoration: none; color: #eacb3c">Unsubscribe here </a>
</td>
</tr>
<!-- Spacing -->
<tr>
<td width="100%" height="20"></td>
</tr>
<!-- Spacing -->
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!-- End of postfooter -->
</html>
server /server/sendMail.js
服务器 /server/sendMail.js
Meteor.methods({
sendEmail: function (to, from, subject, text) {
check([to, from, subject, text], [String]);
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://dev@anderskitson.ca:F0EC-random@smtp.mandrillapp.com:587';
});
Try calling Email.send with an html
parameter instead of a text
parameter: 尝试使用html
参数而不是text
参数调用Email.send :
Email.send({
to: to,
from: from,
subject: subject,
html: text
});
You may want to rename the text
variable to make this more clear and/or consider having one method for plaintext emails and another for HTML-based emails. 您可能需要重命名text
变量以使其更清楚和/或考虑采用一种方法处理纯文本电子邮件,而另一种方法处理基于HTML的电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.