[Tip] Email plugin: sending attachments
by Harjo Kompagnie
www.directict.nl
I have table: email and a related table: attachmentswhere I store all the attachments seperatly in a blob. The table: attachments has important columns: filename (TEXT) (where I store the filename!) and: attachment (MEDIA) (where I store the real attachment).
var msgText = "Hi there"
var subject = "this is a test"
var to = "test@youremail.com"
var from = "bingo@servoy.com"
var cc = ""
var bcc = ""
var attach = new Array()
if(email_to_attachments.getSize() != 0)
{
for ( var i = 0 ; i < email_to_attachments.getSize() ; i++ )
{
var record = email_to_attachments.getRecord(i+1)
attach[i] = plugins.mail.createBinaryAttachment(record.filename, record.attachment)
}
}
var succes = plugins.mail.sendMail(to, from, subject, msgText, cc, bcc, attach);
if (!succes)
{
plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
You can also send attachments that are stored on your local hard drive:
var msgText = "Hi there"
var subject = "this is a test"
var to = "test@youremail.com"
var from = "bingo@servoy.com"
var cc = ""
var bcc = ""
var attachment1 = plugins.mail.createBinaryAttachment('logo1.gif',application.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createBinaryAttachment('logo2.gif',application.readFile('c:/temp/another_logo.gif'));
var succes = plugins.mail.sendMail(to, from, subject, msgText, cc, bcc, new Array(attachment1,attachment2));
if (!succes)
{
plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
Hope this helps! SERVOY ROCKS!
Comments (1)