email msg body

28 views
Skip to first unread message

Hasan Yousef

unread,
Jan 11, 2014, 5:41:12 AM1/11/14
to part...@googlegroups.com
Hi Peter..
I'm testing the email in partial, but looks not clear tome how to make the body of the msg, I tried following the same concept in your example, but with no model data, and got the error in the attached.

Kindly advise.
Thanks.
msgerr.png

Peter Širka

unread,
Jan 11, 2014, 5:46:08 AM1/11/14
to part...@googlegroups.com
Hi Hasan,

the problem is in:

// render view to string
var msgBody = self.view('email', null, true);
// ...
// ...
// ...
// ... message.send(...)
// prevent timeout
self.empty();

Thanks :-)

Hasan Yousef

unread,
Jan 11, 2014, 6:06:44 AM1/11/14
to part...@googlegroups.com
HiPeter,
I tried the below, still getting the same

   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();


Peter Širka

unread,
Jan 11, 2014, 6:13:25 AM1/11/14
to part...@googlegroups.com
Please write me output of:
console.log(typeof(msgBody), msgBody);

Thanks

Hasan A Yousef

unread,
Jan 11, 2014, 6:32:21 AM1/11/14
to part...@googlegroups.com
Kindly see attached.
konsole.txt

Peter Širka

unread,
Jan 11, 2014, 6:39:00 AM1/11/14
to part...@googlegroups.com
This must work:

var msgBody = self.view('email', null, true);

Please, check your code again!

Hasan A Yousef

unread,
Jan 11, 2014, 6:49:29 AM1/11/14
to part...@googlegroups.com
I used exact statement!


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();
}



Hasan A Yousef

unread,
Jan 11, 2014, 6:57:21 AM1/11/14
to part...@googlegroups.com
Hi Peter..
I tried creating a model from mySQL, but looks the data is not moving out of the mySQL connect pool, how can I get the data, so I move it to the mail body template, and be able to send the email with the data


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();
}


Peter Širka

unread,
Jan 11, 2014, 7:02:01 AM1/11/14
to part...@googlegroups.com
I found a bug and I fixed it.

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');

}

Thanks

Peter Širka

unread,
Jan 11, 2014, 7:04:49 AM1/11/14
to part...@googlegroups.com
Yes because data is returned into the callback.
This is correct:

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();  
});

Hasan Yousef

unread,
Jan 11, 2014, 7:56:16 AM1/11/14
to part...@googlegroups.com
even with model data, show the same error.
err.png

Hasan Yousef

unread,
Jan 11, 2014, 11:24:20 AM1/11/14
to part...@googlegroups.com
Finally it is done...
the bug is no self.json, or another self.view should appear in the controller.
Thanks Peter

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.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' });
        });
    connection.end();
    }); 
}


Peter Širka

unread,
Jan 12, 2014, 8:46:42 AM1/12/14
to part...@googlegroups.com
Yes, I fixed it in new version.
Thanks!

Hasan Yousef

unread,
Jan 22, 2014, 11:58:52 PM1/22/14
to tot...@googlegroups.com, part...@googlegroups.com
Hi Peter.
Not sue f this question related to framework or something else, anyhow, I'll ask :)

In the mail, I can send html file, is there a way that the sent item be .pdf,

Regards,
Hasan
Message has been deleted

Peter Širka

unread,
Jan 23, 2014, 3:19:14 AM1/23/14
to tot...@googlegroups.com, part...@googlegroups.com
Hi Hasan,
no :-( ... you can send PDF as attachment. Theoretically is it possible, but you must create own SMTP sender :-) ... and this is complicated.

Thanks :-)

Hasan A Yousef

unread,
Feb 3, 2014, 10:52:38 AM2/3/14
to tot...@googlegroups.com, part...@googlegroups.com
Hi Peter..
Is there an easy way to integrate jsPDF with total.js, so that we can send the email as pdf attachement


thanks

Peter Širka

unread,
Feb 3, 2014, 11:01:12 AM2/3/14
to tot...@googlegroups.com, part...@googlegroups.com
Maybe yes. You must create a PDF file in a server side, but this component is a client-side component.
Thanks :-)

Message has been deleted

Hasan A Yousef

unread,
Feb 3, 2014, 12:12:30 PM2/3/14
to tot...@googlegroups.com, part...@googlegroups.com
Thanks Peter,,
Then this may solve my issue, I was able to create the pdf file by global function, do u have any comments about the methodology I used :)


controller -> default.js
self.global.pdfDoc('fname', 'title', 'body', 'author','subject');



definitions -> global.js
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);

};


Reply all
Reply to author
Forward
0 new messages