Friday, July 22, 2011

Servoy TIP: How To Automate Sending Mail from Gmail

I recently needed to create some functionality to send mail via my Gmail account from within Servoy. It sounds pretty straight forward, but it turned out that there was one parameter that tripped me up. If you don't include this line of code - it won't send email, no matter what you try:


Took me a little while of digging on the Internet and trying stuff to get it to work. So, for this week's tip - I thought it might be a good idea to share the code:

function sendEmailUsingGmail()
       var properties = new Array();
       properties[0] = '';
       properties[1] = 'mail.smtp.port=587';
       properties[2] = 'mail.smtp.auth=true';
        properties[3] = 'mail.smtp.username=';
       properties[4] = 'mail.smtp.password=';
       properties[5] = 'mail.smtp.starttls.enable=true';
        var msgText = 'test message';
        var success = plugins.mail.sendMail('', '', 'subject', msgText, null, null, null, properties);
        if (!success) 
              plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');


No comments:

Web Analytics