cancel
Showing results for 
Search instead for 
Did you mean: 

Sending km document as an email attachment

Former Member
0 Kudos

Hi all,

I am trying to send a KM document as email attachment with the following peice of code. But I am getting FileNotFoundExceptio. Can anyone guide me as to where its going wrong. Any help will be appreciated.


String filePath = "";
ResourceContext ctx = new ResourceContext(getEP5User());
RID rid = RID.getRID("/documents/LRForms/0000000054.pdf");
IResource pdfResource =ResourceFactory.getInstance().getResource(rid, ctx);
filePath =
	"irj\servlet\prt\portal\prtroot\com.sap.km.cm.docs\"
		+ pdfResource.getRID().toString();
Properties props = new Properties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(session);
Address toAddress;
Address fromAddress;
Address ccAddress;
Address bccAddress = new InternetAddress();
MimeMultipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
fromAddress = new InternetAddress("someone@domain.com");
message.setFrom(fromAddress);
toAddress = new InternetAddress("againsomeone@domain.com");
message.setRecipient(Message.RecipientType.TO, toAddress);
message.setSubject("Subject");
messageBodyPart.setText("Please find attached the details.");
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filePath);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(source.getName());
messageBodyPart.setHeader("Content-Type", "application/pdf");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message); 

On executing this code I am getting following exception.

MessagingException javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException

Thanks and regards,

Jaydeep

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

The file path for the document will be like this

/irj/go/km/docs/documents/LRForms/0000000054.pdf

Regards,

Beevin.

former_member182374
Active Contributor
0 Kudos

Hi,

Did you check permissions/security zone settings on the folder/file?

Can you access the file directly from the browser?

Regards,

Omri

Former Member
0 Kudos

Hi Omri,

I can access the file from the browser.

Thanks and regards,

Jaydeep