Email Attachments

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Email Attachments

Postby alasdairs » Tue Apr 16, 2024 2:41 pm

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
Software Engineer
alasdairs
 
Posts: 48
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet

Re: Email Attachments

Postby rafig » Tue Apr 16, 2024 3:54 pm

Try
Code: Select all
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]);
Servoy Certified Developer
Image
rafig
 
Posts: 715
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Email Attachments

Postby alasdairs » Wed Apr 17, 2024 2:56 pm

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:
Code: Select all
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
Software Engineer
alasdairs
 
Posts: 48
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet

Re: Email Attachments

Postby mboegem » Wed Apr 17, 2024 3:16 pm

Hi Alasdair,

you need to use 'createBinaryAttachment' instead of the text variant
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1759
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Email Attachments

Postby rafig » Wed Apr 17, 2024 4:18 pm

Alasdair,
as Marc said (& as I put in my code above), use createBinaryAttachment...
Servoy Certified Developer
Image
rafig
 
Posts: 715
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: Email Attachments

Postby alasdairs » Wed Apr 17, 2024 4:27 pm

Yeah sorry, didn't read it correctly. It's working now.
Software Engineer
alasdairs
 
Posts: 48
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 4 guests