on 01-13-2008 4:06 PM
Hi all,
I have a requirement, i need to create a upload for the user to upload the pdf from his system and after uploading, the user can click on the send email button to send the uploaded pdf document to another person. How do i achieve that? Is there any source code or sample to follow?
Regards,
Rayden
Hi Rayden,
You can use the java mail api for this.
For reference you can use these two PDF's
[1. Sending Mail in Web Dynpro|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2678e05a-0701-0010-fa86-ddfbec5a2b94]
[2. Sending Attachement in web dynpro|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cacb9a7d-0c01-0010-1281-be4962c9ab3e]
Regards
Sid
Edited by: siddharth chauhan on Jan 14, 2008 10:49 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi siddharth chauhan,
The tutorial given is only allow to upload only a standard pdf with template.
String filename =
"temp
webdynpro
web
local
TutWD_EmailInteractiveForm_Init
Components
com.sap.tut.wd.emailinteractiveform.EmailInteractiveFormComp
TravelRequest.pdf";
My application must be dynamic in a way that any pdf file uploaded, the pdf file will be attached as an attachment and send as an email. The path must be dynamic. Is that possible to achieve in java web dynpro?
Regards,
Rayden
Edited by: Rayden on Jan 14, 2008 4:11 PM
Hi Rayden,
Use the code below:
DataSource source = wdContext.currentContextElement().getResource();
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName((resource.getResourceName());
messageBodyPart.setHeader("Content-Type","application/"+resource.getResourceType().getFileExtension());
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
Resource is the VA binded to the RESOURCE property of the upload UI element.
Regards
Sid
Hi siddharth chauhan ,
I try your code.
DataSource source = wdContext.currentContextElement().getFileResource();
The above code giving an error:
Type mismatch: Cannot convert from IWDResource to DataSource.
So I modify the code to FileDataSource as shown:
File newFile = new File(wdContext.currentContextElement().getFileResource().toString());
boolean isFile = newFile.isFile();
boolean isdir = newFile.isDirectory();
boolean isAbs= newFile.isAbsolute();
FileDataSource source = new FileDataSource(newFile.getAbsoluteFile());
mbp1.setDataHandler(new DataHandler(source));
mbp1.setFileName(res.getResourceName());
mbp1.setHeader("Content-Type","application/" + res.getResourceType().getFileExtension());
mp.addBodyPart(mbp1);
msg.setContent(mp);
Transport.send(msg);
I do debugging the following result :
isFile = false
isdir = false
isAbs= false
Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException: ..\..\local\UploadEmailPjt\UploadEMail\~wd_key123_1200360661453\1.pdf?sap-wd-download=1&sap-wd-cltwndid=82bfc481c30911dcc4b00015605b280a&sap-wd-appwndid=82bfc482c30911dc8bff0015605b280a&sap-wd-norefresh=X (The system cannot find the path specified)
-
I try to modify the code to URLDataSource as shown:
URL newurl = new URL(wdContext.currentContextElement().getFileResource().toString());
String pro = newurl.getProtocol();
String newfilez = newurl.getFile();
String urlpath = newurl.getPath();
URLDataSource urlsrc = new URLDataSource(newurl);
mbp1.setDataHandler(new DataHandler(urlsrc));
mbp1.setFileName(res.getResourceName());
mbp1.setHeader("Content-Type","application/" + res.getResourceType().getFileExtension());
mp.addBodyPart(mbp1);
msg.setContent(mp);
Transport.send(msg);
I encounter the following error at URL newurl = new URL(wdContext.currentContextElement().getFileResource().toString());
no protocol: ../../local/UploadEmailPjt/UploadEMail/~wd_key121_1200360322468/1.pdf?sap-wd-download=1&sap-wd-cltwndid=b9f4b8d3c30811dcc3870015605b280a&sap-wd-appwndid=b9f4b8d4c30811dcca950015605b280a&sap-wd-norefresh=X
The path
../../local/UploadEmailPjt/UploadEMail/~wd_key121_1200360322468/1.pdf?sap-wd-download=1&sap-wd-cltwndid=b9f4b8d3c30811dcc3870015605b280a&sap-wd-appwndid=b9f4b8d4c30811dcca950015605b280a&sap-wd-norefresh=X
is generated by the web dynpro, when i upload the file. When i create a link to download the file using the path, it work fine. But when i try to use the link to attach the file in the email as an pdf, it cant. Why is that so? Any idea how to attach the pdf?
Regards,
Rayden
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.