如何在流星项目中添加包含嵌入html代码的电子邮件模板 [英] How to add email template containing embed html code in meteor project

查看:110
本文介绍了如何在流星项目中添加包含嵌入html代码的电子邮件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是流星js的新手.您能否建议我如何在流星项目中添加包含嵌入html代码的电子邮件模板.我尝试了一些软件包,但没有用.请提供示例示例进行解释.

I am new to meteor js. Could you please suggest me how to add email template containing embed html code in meteor project. I had tried few packages,but its not working.Could you please explain with a sample example.

注意:当用户注册到我的网站时.我们俩(新用户和我)都必须获取电子邮件.两者都包含不同的嵌入html内容.

Note: When a user register into my site. Both of us (new user and me) have to get the email. Both contains different embed html content.

推荐答案

下面是一个基本示例,假设您使用blaze:

Here is a basic example assuming you use blaze:

在您的模板事件中:

var email = emailAddress; //define emailAddress
var dataContext = {
    yourname: getDataFromSomewhere; //whatever you define in dataContext is used in email template
};
var html = Blaze.toHTMLWithData(Template.mailTemplateName, dataContext);
Meteor.call('sendMail', yourname, email, html); 

邮件模板:

<template name="mailTemplateName">
    <h3>Hello {{yourname}}</h3>
</template>

方法内部:

sendMail: function(yourname, email, html) {
    this.unblock();
    var options = {
      from:"from@from.com",
      to: email,
      subject: 'Mail subject field',
      html: html
    };
    Email.send(options)
}

您只需要电子邮件软件包(控制台中的meteor add email或将email添加到您的软件包中)并配置SMTP即可正常工作.电子邮件包和用法的文档此处

You only need email package (meteor add email in console or add email to your packages) and configure SMTP for this to work. Documentation for email package and usage here

SMTP配置示例(在服务器中!)

SMTP configuration example (in server!)

Meteor.startup(function () {
    smtp = {
    username: 'someMail@something.com',
    password: 'password here',  
    server:   'server.something.com',
    port: 25 //change with correct port
}

process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) //+ ':' + smtp.port;
});

如果这段代码中发生了什么,您可以轻松地使用它并使用不同的html模板发送包含不同数据的不同电子邮件

If you get whats going on in this code, you can easily play with it and send different emails with different data using different html templates

这篇关于如何在流星项目中添加包含嵌入html代码的电子邮件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆