1
私はNodejsの初心者であり、いくつかの記事を参照して学習しようとしていますので、私と一緒に裸にしてください。NodeJS:アジェンダを使用した電子メールのスケジュール
私はしかし、私はindex.js
に以下のコードで起こって何も表示されない、NodeMailerとアジェンダを使用して電子メールを送ったにスケジュールしようとしています:
var Agenda = require('agenda');
var agenda = new Agenda();
const nodemailer = require('nodemailer');
agenda.define('send email', {priority: 'high', concurrency: 10}, function(job, done) {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'xxxx'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Test" <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, response) {
console.log('Message sent: ' + response.message);
transporter.close();
done();
});
});
agenda.on('ready', function() {
agenda.every('5 seconds', 'send email');
agenda.start();
});
agenda.on('start', function (job) {
console.log("Job %s starting", job.attrs.name);
});
agenda.on('complete', function (job) {
console.log("Job %s finished", job.attrs.name);
});
console.log('Wait 10 seconds...');
Iをnode index.js
を使用して上記のコードを実行すると、次のコンソールメッセージが表示されます。
基本的に、私は5秒ごとに実行する電子メール機能をスケジュールしようとしています。
どこが間違っていますか?
EDIT:その上記のコマンドを実行しているから、希望取得する方法があるので、もし私が、しかし実際に後のジョブオブジェクトが必要
agenda.every('5 seconds', jobName);
:対ジョブ実装であると思われます容認できる答えである。
、ちょうどSMTPサーバー – Kanchana
は私は全く別の問題ではと思った、私の他のコメントを無視します。議題はモンゴーに依存している。それは、それがすべての仕事を保存するところです。だから、あなたがmongoを立ち上げていないなら、彼らは動かないだろう。 – user1427105