Hi,
I used mailapi.jar to send a mail from java program.
Attached a pdf to the mail and sent to multiple users.
Here is the code:
------------------------------------------------------------------------------------------------
try{
File file=new File("report.pdf");
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
// data is pdf byte array fo the pdf file//
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent("This is a test mail with PDF attachment<br><br><br>", "Text/HTML");
mp.addBodyPart(htmlPart);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
DataSource dataSource = new FileDataSource(file)
{
public String getContentType()
{
return "application/pdf";
}
};
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
mimeBodyPart.setFileName(file.getName());
mimeBodyPart.setHeader("Content-Transfer-Encoding", "base64");
mimeBodyPart.setDisposition(Part.ATTACHMENT);
mp.addBodyPart(mimeBodyPart);
msg.setContent(mp);
Transport.send(msg);
}
catch (Exception e) {
System.out.println("Error Message: "+e);
e.printStackTrace();
}
------------------------------------------------------------------------------------------------
Regrads,
PJ.
Paul Yu wrote:
Raymond
I have not done this in a complete loop, so you will need to experiment.
But the basic process would be something like this.
1) Do the PDF generation, but return the response into an NSData
2) Then follow the pattern in Pascal's link to put the NSData as content on the
message.addAttachment(new ERMailDataAttachment("myattachment.pdf", null, content));
Paul
On Dec 7, 2011, at 7:11 AM, Pascal Robert wrote:
Have a look at ERJavaMail, you can send attachments with it.
http://wiki.objectstyle.org/confluence/display/WO/Project+WONDER-Frameworks-ERJavaMail
Hi Paul,
I would like to get the pdf file and sent it directly by mail with a method. How can I get the the file in the pdfReport component?
Thanks for your help.
Envoyé depuis iCloud
Le 17 nov 2011 à 07:06, Paul Yu <email@hidden> a écrit :
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden