Emailing A PDF Attachment using plugin

Version 3.1.7-build 411
Java version 1.6.0_02-b06 (Windows XP)

Hello all,

I ddi this in a old version of servoy a few years back. I am trying to create and email a PDF. Here is my code… The globals are the recepient, subject and email body. When i run the code I recieve the faliure message I created. I have tried debugging but I am not sure how to trouble shoot. I did set up my mail server prefereces. Any Ideas ??

//prints the current form as a 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();

//email thePDF as an attachment
var attachment1 = plugins.mail.createBinaryAttachment(‘fax.pdf’,thePdf);

var succes = plugins.mail.sendMail(globals.G_Text1,‘Ebrandt@surgicam.com’, globals.G_Text2,globals.G_Text3,null,null,new Array(attachment1));

if (!succes)
{
plugins.dialogs.showWarningDialog(‘Alert’,‘Failed to Send Email’,‘OK’);
}

Does you servoy log tell you anything?

Where is the authorization array? I’m not seeing anything related to authorization in your code or your call to the sendmail plugin.

Something like this:

var authorization = new Array("mail.smtp.host=smtp.mail.yahoo.com", "mail.smtp.auth=true", "mail.smtp.username=yahooname", "mail.smtp.password=mypw");

My sendmail code looks like this:

var authorization = new Array("mail.smtp.host=smtp.mail.yahoo.com", "mail.smtp.auth=true", "mail.smtp.username=yahooname", "mail.smtp.password=mypw");

var emailSend = 'recipient@youraddress.com';
var emailFrom = "Display Name for Sender<sender@myaddress.com>";
var emailSubject = "Test subject";
var emailMsg = 'Test message'

var success = plugins.mail.sendMail(emailSend, emailFrom, emailSubject, emailMsg, null, null, null, authorization );

I am just now learning to do attachments, so I’ll borrow your code for that and hopefully this code helps you figure your issue out. Good luck. Hope this helps.

Learning at the speed of Servoy…gotta love it!

I got the email attachments figured out. Here’s my code that’s working.

// additional code above eliminated for brevity

// create a file object
var file = plugins.file.showFileSaveDialog();

/*
  I have add'l code not showing that creates an Excel file and saves it
*/

// Get the filename of the file we just saved to disk
var filename = file.getAbsoluteFile();

// here's where the emailing starts

var authorization = new Array("mail.smtp.host=smtp.mail.yahoo.com", "mail.smtp.auth=true", "mail.smtp.username=yahooname", "mail.smtp.password=mypw");

// read the file into a file object
var rawData = plugins.file.readFile(filename)

// convert the file to a binary attachment
var myFile = plugins.mail.createBinaryAttachment('test.xls', rawData)

// put the binary file into an array in preparation for the email plugin
var attachment = new Array(myFile);

// confirm send
var answer = plugins.dialogs.showWarningDialog('Alert', 'You are about to email this Excel file to the customer', 'OK', 'Cancel');

if(answer == 'OK')
 {
  var emailSend = 'recipient@yahoo.com' 
  var emailFrom = "sender<sender@yahoo.com>";
  var emailCC = "cc@yahoo.com"
  var emailBCC = "bcc@yahoo.com"
  var emailSubject = "Testing email with attachment";
  var emailMsg = 'This is the message'

  var success = plugins.mail.sendMail(emailSend, emailFrom, emailSubject, emailMsg, emailCC, emailBCC, attachment, authorization );
 }
// What was the result of trying to send the email
plugins.dialogs.showInfoDialog('Email Sent', 'Email sent successfully? ' + success,'OK');

There may or may not be some useful tidbits in this blog post I did a while back…

http://greg.agiletortoise.com/2007/02/0 … ilprinter/

I shows example code for creating a multi-destination print dialog that can PDF, or email a PDF, or just plain old print.

greg.