我是流星js的新手。您能否請我建議我如何在流星項目中添加包含嵌入式html代碼的電子郵件模板。我曾嘗試過幾個軟件包,但它不能正常工作。請您舉例說明一下。如何在meteor項目中添加包含嵌入html代碼的電子郵件模板
注:當用戶註冊到我的網站。我們兩個人(新用戶和我)都必須收到電子郵件。兩者都包含不同的嵌入式html內容。
我是流星js的新手。您能否請我建議我如何在流星項目中添加包含嵌入式html代碼的電子郵件模板。我曾嘗試過幾個軟件包,但它不能正常工作。請您舉例說明一下。如何在meteor項目中添加包含嵌入html代碼的電子郵件模板
注:當用戶註冊到我的網站。我們兩個人(新用戶和我)都必須收到電子郵件。兩者都包含不同的嵌入式html內容。
昨天我很幸運地實施了這個要求。下面是使用電子郵件包發送HTML的方向。
執行命令;
meteor add email
meteor add meteorhacks:ssr
創建HTML,這將是訪問由服務器。
下面是在項目的HTML代碼示例/ email.html添加電子郵件包
<template name="email">
<table>
<tr>
<td></td>
<td width="600">
<table>
<tr>
<th>Name</th>
<td>{{name}}</td>
</tr>
<tr>
<th>Age</th>
<td>{{age}}</td>
</tr>
</table>
</td>
</tr>
</table>
</template>
在SERVER/main.js文件,你需要使用導入的包,
import { Email } from 'meteor/email';
Meteor.startup(() => {
//fill EMAIL_ID, PASSWORD
process.env.MAIL_URL = "smtp://EMAIL_ID:[email protected]:465";
SSR.compileTemplate('htmlEmail', Assets.getText('email.html'));
var emailData = {
name: "Jishnu S",
age: "25"
};
Email.send({
to: "[email protected]",
from: "email_ID",
subject: "Example Email",
html: SSR.render('htmlEmail', emailData)
});
});
上面的代碼是用於啓用gmail SMTP配置的電子郵件。 查收電子郵件和Voila .. !!!!有用。請享用!快樂的編碼!
這是一個基本的例子,假設你使用火焰:
在模板事件:
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:"[email protected]",
to: email,
subject: 'Mail subject field',
html: html
};
Email.send(options)
}
你只有ne ed電子郵件包(控制檯中的meteor add email
或將email
添加到您的軟件包中)並配置SMTP以使其起作用。文檔的電子郵件包和使用率here
SMTP配置示例(服務器!)
Meteor.startup(function() {
smtp = {
username: '[email protected]',
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模板
嗨!我測試了你的代碼,但是我的錯誤:無法在我的控制檯上找到模塊'./email.html':(相對路徑是正確的 –
你的目錄結構是什麼? –