I am diving into email support within servoy. I want to be able to send a PDF via email. I will have a method set up for the user to choose a email address, then I was hoping to be able to create the pdf, attachment. I was hoping that the user would see the email with the attachment open up via outlook, so they could then add text to the body and hit send.
I know there are many ways this can be accomplished, but I wanted to keep it simple. I can set up exchange 2000 / 2003 to allow the host to send emails via SMTP.
I know that there are several plugins and built in PDF functions within servoy, but have read some threads that outlined some issues.
I have personally only manully created PDF’s in Filemaker and had to save the file to a location, then send it manually.
I really don’t need to save the pdf in a location, just send it as an attatchment.
I was hoping that someone might be able to tell me which is the best / easiest technique to accomplish this, I don’t major detail, just a point in the right direction.
Best is to use Servoy’s pdf plugin and mail plugin. All you need is this:
//print the current form as pdf into a variable
var success = plugins.pdf_output.startMetaPrintJob()
if (success)
{
controller.print(true,false,plugins.pdf_output.getPDFPrinter());
}
var thePdf = plugins.pdf_output.endMetaPrintJob()
var attachment1 = plugins.mail.createBinaryAttachment('fax.pdf',thePdf);
var succes = plugins.mail.sendMail('to_email@someone.com',
'fromemail@servoy.com', "Here's a pdf", '',null,null,new Array(attachment1));
if (!succes)
{
plugins.dialogs.showWarningDialog('Alert','Failed to send email','OK');
}
obviously instead of the hardcoded addresses above you can also use variables, fields, etc, etc
This works really well, but I have a couple questions:
Title borders, the title appears as strikes through, I guess its a pdf rendering issue, no big deal.
If the form I want to print is created from the line item table, and I have the correct found set, how can I print all the line items, not just line item I am on.
How can I preview through the mail client (outlook), in the creation state so the user can and text to the body, and send manually. I can see where I can add a field to enter body text into, but think it would be nice for the user to see the email as the would with their mail client
Haven’t done much with PDF but couple of suggestions:
Have you tried creating the PDF form in the line item table using List or Table layout with Headers/Footers for rest of details
Rather than send data to Outlook it might be easier to use the Servoy SendMail functions then you can provide users with whatever editing ability they need and keep all the information - email text and attachments - within your Servoy solution.
jaleman:
Best is to use Servoy’s pdf plugin and mail plugin. All you need is this:
//print the current form as pdf into a variable
var success = plugins.pdf_output.startMetaPrintJob()
if (success)
{
controller.print(true,false,plugins.pdf_output.getPDFPrinter());
}
var thePdf = plugins.pdf_output.endMetaPrintJob()
var attachment1 = plugins.mail.createBinaryAttachment(‘fax.pdf’,thePdf);
var succes = plugins.mail.sendMail(‘to_email@someone.com’,
‘fromemail@servoy.com’, “Here’s a pdf”, ‘’,null,null,new Array(attachment1));
if (!succes)
{
plugins.dialogs.showWarningDialog(‘Alert’,‘Failed to send email’,‘OK’);
}
obviously instead of the hardcoded addresses above you can also use variables, fields, etc, etc
Substituting my email address in above, I can not get it to work. Is there something missing?
jaleman:
Best is to use Servoy’s pdf plugin and mail plugin. All you need is this:
//print the current form as pdf into a variable
var success = plugins.pdf_output.startMetaPrintJob()
if (success)
{
controller.print(true,false,plugins.pdf_output.getPDFPrinter());
}
var thePdf = plugins.pdf_output.endMetaPrintJob()
var attachment1 = plugins.mail.createBinaryAttachment(‘fax.pdf’,thePdf);
var succes = plugins.mail.sendMail(‘to_email@someone.com’,
‘fromemail@servoy.com’, “Here’s a pdf”, ‘’,null,null,new Array(attachment1));
if (!succes)
{
plugins.dialogs.showWarningDialog(‘Alert’,‘Failed to send email’,‘OK’);
}
obviously instead of the hardcoded addresses above you can also use variables, fields, etc, etc
Substituting my own email address in the to and from in the above code, I can not get it to work. Could there be something missing?
Have you tried creating the PDF form in the line item table using List or Table layout with Headers/Footers for rest of details
Thats what I am doing, the only way to really creatve a invoice that can have unlimited line items.
Rather than send data to Outlook it might be easier to use the Servoy SendMail functions then you can provide users with whatever editing ability they need and keep all the information - email text and attachments - within your Servoy solution.
I can re-create the email with a new form, but was hoping to avoid that.
Substituting my own email address in the to and from in the above code, I can not get it to work. Could there be something missing?
Jan’s Example code worked perfectly for me, all I did was change the addresses.
I was still hoping to solve this line item form issue if anyone haas any insight.
I have a related question as I’m doing the same thing except that I’m not sending the PDF, I’m just sending a dynamic message based on form fields. I am trying to create a PDF of the form though if the sendMail function fails… here’s where my question comes in:
The form I have has no controller - it’s just a bunch of input fields tied to global variables. Is there some other way to print without using the controller? If not, is there a way to make the controller invisible or something? I’m new to Servoy so apologize if this is common knowledge.
If you only need the global variables in your email you don’t need to stick them on a form:
emailtext += globals.field1 + ’ some text here ’ + globals.field2
etc etc
Additionally if on a form you uncheck the showInMenu property it will not show up on client (also make sure it is not set to be the firstform in the solution settings)
fdoddridge:
The form I have has no controller - it’s just a bunch of input fields tied to global variables.
All forms have a controller object because every form is (should be) in context with a database table. It also doesn’t matter if the controller is visible on the form or not.
You can place only global fields on it but that doesn’t change the method of working here.
Just use the formwithglobals.controller for your PDF creation.