var SITE_URL = Meteor.absoluteUrl();
function sendEmailNotification(type, sourceUser, recipients, notificationObject) {
var emailFrom = '[email protected]';
var emailSubject = 'MyApp: ';
var emailBody = '';
$.each(recipients, function (index, recipient) {
recipients[index] = recipient + '@example.com';
});
switch(type) {
case 'item_assigned':
emailSubject += notificationObject.item_title;
emailBody += '<div style="padding:10px;">';
emailBody += sourceUser;
emailBody += ' has assigned you an action item';
emailBody += '</div>'
break;
case 'list_shared':
emailSubject += notificationObject.list_title;
emailBody += '<div style="padding:10px;">';
emailBody += sourceUser;
emailBody += ' has shared a list with you: ';
emailBody += '<a href="' + SITE_URL + '#' + notificationObject.list_id + '">' + notificationObject.list_title + '</a>';
emailBody += '</div>'
break;
}
if (Meteor.isServer) {
// This function only runs on server
Email.send({
from: emailFrom,
bcc: recipients,
subject: emailSubject,
html: emailBody
});
}
}
上述函數位於根文件中(因此它的代碼對客戶端和服務器都可用)。但是當我在我的客戶端代碼中調用它時,什麼也沒有發生。我的應用程序中包含了email
軟件包。在我的本地機器上(Windows 7),我沒有MAIL_URL
變量集。所以調用Email.send()
函數理想情況下應該在命令提示符下產生輸出,但實際上沒有輸出。meteorjs:我正確使用Email.send()嗎?
在我們的生產服務器上,SMTP已正確設置,其他應用程序可以使用相同的設置發送電子郵件。我在那裏正確配置了MAIL_URL
環境變量,但仍然沒有發送郵件。
有人可以告訴我,如果我的代碼有問題嗎?有什麼我不正確的做法?
P.S .:我甚至嘗試直接調用Email.send(),如下面的代碼,但仍然沒有發生任何事情。
if (Meteor.isServer) {
Email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'This is a test email',
html: '<b>Congrats, it works!</b>'
});
}
}
});
您也可以發表您的解決方案作爲一個答案,你自己的問題,這都將獲得你的聲譽以及幫助未來的遊客! – Rahul