« [tip] How to avoid errors on relations | Main | [Showcase] using Dashboard Widgets with Servoy »
July 15, 2005
[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!
| Posted by David Workman on July 15, 2005 at 03:11 PM in Tips | Permalink
Comments
Harjo
This is great tip and proof that you can also read minds as I was working on how to add multiple attachments to emails! I've also finally learnt what 'record.xxx' can be used for.
Servoy really does rock and I'm still not out of 2nd gear with it.
Thanks again
Graham Greensall
Posted by: Graham Greensall | Jul 16, 2005 5:54:10 AM