Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Generated PDF attach to Email
Hello Guys , I am learning MailServices of Liferay . In that we get option to adding attachment files also , so I tried to add the pdf with Email . But I am not understanding how to add the File object in mailMessage.addFileAttachment(file) because I am not saving pdf File object anywere in server I will try to directly create the pdf using iText . I am adding my sample code below .Could you please tell the process for resovle this issue.This is great help to me.
Attachments:
Hello Guys ,
I took some reference code But in that PDF file is already placed in resource folder , so that is not my requirement , because in my case I generating dynamically all data always , Could you please tell the process for resovle this issue.This is great help to me. I am attaching below snap where I tried that code and I get attachment with mail But that pdf is alwyas same which is placed inside resource folder. so How to get always newly generated pdf File ?
I took some reference code But in that PDF file is already placed in resource folder , so that is not my requirement , because in my case I generating dynamically all data always , Could you please tell the process for resovle this issue.This is great help to me. I am attaching below snap where I tried that code and I get attachment with mail But that pdf is alwyas same which is placed inside resource folder. so How to get always newly generated pdf File ?
Attachments:
Hi,You can create a Temp file dynamically write on it from PDF writer and use that in attachment , something like below
File file = FileUtil.createTempFile("pdf");
OutputStream os = null;
try {
os = new FileOutputStream(file);
} catch (FileNotFoundException e) {
_log.error(e.getMessage());
}
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(document, os);
} catch (com.itextpdf.text.DocumentException e) {
_log.error(e.getMessage());
}
Hello Yasin ,
Thanks for your valuable suggestions .
I tried this approach , It working fine .. But we any other alternate because we dont want to store the file in server . In this code we are creating tempFile i.e. always storing in server .
Thnak & Regards ,
Pradip
Thanks for your valuable suggestions .
I tried this approach , It working fine .. But we any other alternate because we dont want to store the file in server . In this code we are creating tempFile i.e. always storing in server .
Thnak & Regards ,
Pradip
pradip choudhari:
Looking at MailMessage, it seems to be limited so that you can only add attachments from a file - To generate in memory you'd go with e.g. BufferedOutputStream, but MailMessage's interface always assumes that there's a file to attach.
I tried this approach , It working fine .. But we any other alternate because we dont want to store the file in server . In this code we are creating tempFile i.e. always storing in server .
You could go with the standard (javax) mail API instead of Liferay's, but you'd be missing the mail to be asynchronously sent.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™