// render view to string
var msgBody = self.view('email', null, true);
// ...
// ...
// ...
// ... message.send(...)
// prevent timeout
self.empty();
var msgBody = self.view('email',null,true);
var message = new mail.Message('email subject', msgBody); message.send('smtp.gmail.com', { port: 465, secure: true, timeout: 60000, user: '@gmail.com', password: 'mypswd' }); self.empty();
function view_items_homepage(){ var self = this; self.view('itemsIndex');
var msgBody = self.view('email',null,true);
var message = new mail.Message('email subject', msgBody);
message.reply('ha...@gmail.com'); message.from('ha...@gmail.com','Hasan test'); message.send('smtp.gmail.com', { port: 465, secure: true, timeout: 60000, user: 'ha...@gmail.com', password: 'pswd' }); console.log('type of msgBody: ',typeof(msgBody)); console.log('msgBody: ',msgBody); self.empty();}
function items_json_data() { var self = this; var SQL="Select * from users"; var model={}; var connection = self.database('test');
connection.connect(); connection.query(SQL,function (err, rows) { if (err) {self.view('~/errors/internalServerError'); return; } self.json(rows); utils.extend(model,rows,true); console.log('model inside connection',model); //This is OK, same date in rows }); connection.end();
console.log('model outside connection',model); //This is empty var msgBody = self.view('email',model,true); var message = new mail.Message('email subject', 'test'); message.to('email'); message.reply('email'); message.from('email','name'); message.send(...); self.empty();}
function view_items_homepage(){
var self = this;
// HERE IS BUG: self.view('itemsIndex');
// I FIXED IT IN NEW VERSION
var msgBody = self.view('email',null,true);
var message = new mail.Message('email subject', msgBody);
message.to('ha...@gmail.com');
message.reply('ha...@gmail.com');
message.from('ha...@gmail.com','Hasan test');
message.send('smtp.gmail.com', { port: 465, secure: true, timeout: 60000, user: 'ha...@gmail.com', password: 'pswd' });
console.log('type of msgBody: ',typeof(msgBody));
console.log('msgBody: ',msgBody);
// HERE RETURN A RESPONSE
self.view('itemsIndex');
}
connection.query(SQL,function (err, rows) {
if (err) {
self.view('~/errors/internalServerError');
return;
}
self.json(rows);
utils.extend(model,rows,true);
console.log('model inside connection',model);
connection.end();
var msgBody = self.view('email',model,true);
var message = new mail.Message('email subject', 'test');
message.to('email');
message.reply('email');
message.from('email','name');
message.send(...);
self.empty();
});
function view_items_homepage(){
var self = this; var SQL="Select * from users";
var connection = self.database('test');
connection.connect(function(err) {
connection.query(SQL,function (err, rows) { if (err) {self.view('~/errors/internalServerError'); return; }
var msgBody = self.view('email',rows,true); var message = new mail.Message('email subject', msgBody); message.reply('ha..@gmail.com'); message.from('ha..@gmail.com','Hasan test'); message.send('smtp.gmail.com', { port: 465, secure: true, timeout: 60000, user: 'ha..@gmail.com', password: 'pswd' }); }); connection.end(); }); }
self.global.pdfDoc('fname', 'title', 'body', 'author','subject');
var PDFDocument = require ('pdfkit');
framework.global.pdfDoc = function(fname, title, body, author,subject) { var doc; var output = fname+'.pdf';
doc = new PDFDocument({ info: { Title: title, Author: author, Subject: subject } });
doc.text('This text is justified. ' + body, { width: 410, align: 'justify' });
doc.moveDown();
doc.text('This text is justified. ' + body, { width: 410, align: 'justify' });
doc.write(output);
};