Email Attachments

Hi all,

I have just finished setting up emails, but am wondering how I could attach a pdf to the email. I tried using plugins.mail.createTextAttachment(filename, textdata) but it doesn’t seem to work. Are you meant to just put the filepath of the file you want to send in the filename? I’m not sure what to put in the textdata field.

Thanks,
Alasdair

Try

var attachment_array = plugins.mail.createBinaryAttachment(attachment_name, attachment);
						success = plugins.mail.sendMail(send_to,
							from_email,
							send_subject,
							sendHTML,
							send_cc,
							send_bcc,
							[attachment_array]);

Hi Rafig,

Thanks, that seems to be mostly working but every time I try to open the attachment I have sent it’s a broken file.

Here’s my code:

plugins.mail.createTextAttachment(foundset.order_uuid + '.pdf', scopes.global.pdfPath('Customer_Orders') + foundset.order_uuid + '.pdf')

The error message I get is:

The file “file.pdf” could not be opened.
It may be damaged or use a file format that Preview doesn’t recognise.

Thanks,
Alasdair

Hi Alasdair,

you need to use ‘createBinaryAttachment’ instead of the text variant

Alasdair,
as Marc said (& as I put in my code above), use createBinaryAttachment…

Yeah sorry, didn’t read it correctly. It’s working now.