Attachment from field

I have a field where I load a file

var theFile = plugins.file.showFileOpenDialog();
var rawData = plugins.file.readFile(theFile);
var name = theFile.getName();
forms.act_haeder_email.act_email_attach = rawData

I try to send the e mail with attachment

var to = forms.act_header_email.act_email_to
var cc = forms.act_header_email.act_email_cc
var bcc = forms.act_header_email.act_email_bcc
var from = forms.act_header_email.act_email_from
var subject = forms.act_header_email.act_email_subject
var txt = forms.action_note.act_txt

var attach = plugins.mail.createBinaryAttachment('test',plugins.images.getImage(forms.act_header_email.act_email_attach))

var success = plugins.mail.sendMail(to, from, subject, txt ,cc , bcc , attach, null);
if (!success) 
{

	plugins.dialogs.showWarningDialog('Alert',plugins.mail.getLastSendMailException(),'OK'); 
}

I can send the email but the attachment isn’t sent.

Any suggestions?
[/code]

Uhm, by heart make the attachment an attachment array.

Please try this```
plugins.mail.sendMail(to, from, subject, txt ,cc , bcc , [attach], null);

Thank you Marcel, but no go, it stills doesn’t send the attachment.

With the debugger my var attach is still null

Hi,

Marcel is correct about it needing an array, though

Perhaps this will work:

var attach = new array()
var attach[0] = plugins.mail.createBinaryAttachment('test',plugins.images.getImage(forms.act_header_email.act_email_attach))

var success = plugins.mail.sendMail(to, from, subject, txt ,cc , bcc , attach, null);

Cheers
Harry

You have to make it an binary, like this:

var attachmentBinary = “”;

if(attachment)
{
attachmentBinary = plugins.mail.createBinaryAttachment(attachment_name, attachment)
}

var succes = plugins.mail.sendMail(dataset.getValue(i,3), send_email, msgSubject, msgText,“”,“”,attachmentBinary);

thank you Sanneke, I’ve tried but the variable attachmentBinary remains null.

Is the image really there?
What when you add an (correct) suffix to ‘test’.

Hi Irene,

can you post your complete method here again?
(from what you have now)
what I see in your previous post are indeed 2 mistakes.

de filename must be for example test.pdf
and skip the plugins.image stuff, just fill the attachment with raw data.

Hope this helps

Hello Harjo,

alleluia, it works!!! You where right, the extension in the name was the mistake.

thank you, this forum is awesome.