掲示板

email attachment

12年前 に ruchi sharma によって更新されました。

email attachment

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Hello ,
I am trying to send an email with attachment,
I have kept the attachment file in the portlet source, following is the path
/myportlet-portlet/attachment/trainingeditable.pdf
(lemme know if its right place to keep it or not ).
CODE:
MailMessage message = new MailMessage(from, to, subject, body, true);
message.setCC(cc);
File attachment = new File("/myportlet-portlet/attachment/trainingeditable.pdf");
message.addAttachment(attachment);


Secondly, i am getting the following error while sending email ..... (and i have used this path before for acessing image file and it does works fine)

ERROR [MailEngine:489] IOException while sending message
15:51:00,407 ERROR [MailEngine:154] java.io.FileNotFoundException: /myportlet-portlet/attachment/trainingeditable.pdf (No such file or directory)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at javax.activation.FileDataSource.getInputStream(FileDataSource.java:82)
at javax.activation.DataHandler.writeTo(DataHandler.java:290)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:845)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:361)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:85)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:869)
at javax.activation.DataHandler.writeTo(DataHandler.java:302)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at com.liferay.util.mail.MailEngine._send(MailEngine.java:475)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:366)
at com.liferay.util.mail.MailEngine.send(MailEngine.java:110)
at com.liferay.mail.messaging.MailMessageListener.doMailMessage(MailMessageListener.java:101)
at com.liferay.mail.messaging.MailMessageListener.doReceive(MailMessageListener.java:115)
at com.liferay.mail.messaging.MailMessageListener.receive(MailMessageListener.java:43)

Please let me know where I am wrong and is their other way around to add attachment.
Is their any problem in attachment path ??
Thanks in advance
Ruchi
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: email attachment

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
You should be using getResourceAsStream() to stream the data from the classpath.

new File() for a path such as "/myportlet" means that "/myportlet" is available from the root of the hard drive, not as a path within the webapp.
12年前 に ruchi sharma によって更新されました。

RE: email attachment

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Thanks David, that was really helpful.
thumbnail
12年前 に Jitendra Rajput によって更新されました。

RE: email attachment

Liferay Master 投稿: 875 参加年月日: 11/01/07 最新の投稿
Hi Ruchi,

Try to get file object like this

File f= new File(getPortletContext().getRealPath("/test.csv"));
12年前 に ruchi sharma によって更新されました。

RE: email attachment

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Hello Jitendra,
that's really a eassy way to get the path of the file.
problem solved.
many thanks
ruchi
9年前 に Eswaran R によって更新されました。

RE: email attachment

Junior Member 投稿: 82 参加年月日: 14/12/29 最新の投稿
Hi ruchi sharma,,

can u send me full email attachment coding ????

thanks..

Regards ...

Eswaran R