cancel
Showing results for 
Search instead for 
Did you mean: 

How to email PDF form as an attachment?

Former Member
0 Kudos

Hi All,

I have developed online interactive form app(dynamic).

When user clicks the submit button after entered the data,

I want to email the PDF form as an attachment to some users.

Could anyone please explain the steps or give me some sample code?

Thanks

Sundar

Accepted Solutions (0)

Answers (3)

Answers (3)

i042339
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi All,

I hope the following approach will solve all your problem.

For sending the PDF file filled by the User to an email address as an attachment

a. Create a Button

b. Choose control type as Submit

c. Go to Submit Tab and select Submit field as PDF

d. In the URL field mention - mailto : email address (for example mailto : workflow@test.com)

Thanks

Satya

Former Member
0 Kudos

I found this in one of the forums dont remember which, here is the code

public boolean EmailForm( java.lang.String pernr, java.lang.String toEmail, java.lang.String fromEmail )

{

//@@begin EmailForm()

boolean flag = true;

try {

String host = "exchangerelay.yourserver.com";

// Get system properties

Properties props = System.getProperties();

// Setup mail server

props.put("mail.smtp.host", host);

// Get session

Session session = Session.getDefaultInstance (props, null);

// Define message

MimeMessage message = new MimeMessage(session);

byte[] b = wdContext.currentContextElement().getPdfSource();

//Attachment

ByteArrayInputStream ba = new ByteArrayInputStream(b);

String filename ="Filename.pdf";

//This will create a file on the server under folder "server0"

File file = new File(filename);

FileOutputStream fos = new FileOutputStream(file);

int i = 0;

for (i = 0; i < b.length; i++) {

fos.write(b<i>);

}

fos.close();

DataSource source = new FileDataSource(file);

BodyPart messageBodyPart = new MimeBodyPart();

message.setFrom(new InternetAddress(fromEmail));

message.addRecipient(

Message.RecipientType.TO,

new InternetAddress(toEmail));

message.setSubject ("Subject : ");

message.setText(

"This is a confirmation receipt.");

Multipart multipart = new MimeMultipart();

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setHeader("Content-Type", "application/pdf");

messageBodyPart.setFileName(filename);

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

Transport transport = session.getTransport("smtp");

transport.connect(host, "username", "password");

transport.sendMessage(message, message.getAllRecipients());

transport.close();

flag = true;

//delete file if you want to here

file.delete();

} catch (FileNotFoundException e) {

flag = false;

wdComponentAPI.getMessageManager().reportException(

"FileNotFoundException : " + e.getMessage(),

false);

} catch (IOException e) {

flag = false;

wdComponentAPI.getMessageManager ().reportException(

"IOException : " + e.getMessage(),

false);

} catch (MessagingException e) {

flag = false;

wdComponentAPI.getMessageManager().reportException(

"MessagingException : " + e.getMessage(),

false);

}

return flag;

//@@end

}

thanks,

Sanketh

Former Member
0 Kudos

Hi Sundar,

for sending email you can use the javascript below. Use the Button from the group Standard and move javascript to click event.

var myDoc = event.target;
try {
  myDoc.mailDoc({
    bUI: false,
    cTo: "email@aa.com",
    cCC: "",
    cSubject: "Subject",
    cMsg: ""
  });
} catch (e) {}

Regards

Michal

Former Member
0 Kudos

hi Sundar,

Did you find a solution ? We have a similar requirement, please let me know how you solve dit.

thanks,

Sanketh

Former Member
0 Kudos

Hi,

One solution is above...

If your end-user doesn't have an email client, another one consists of using the SMTP server, which runs on the J2EE engine, to send an email with the form in attachment. Of course, this requires more Web Dynpro and Java coding...

Regards,

Francois

Former Member
0 Kudos

hi Francois,

I aware of using Java mail api to email, but how to get hold of the PDF file. Can we use context attribute "pdfSouce" binary type to get the pdf attachment ?or is the content type attached in xml data format? My requirement is to send the exact pdf attachment.

thanks,

Sanketh

Former Member
0 Kudos

Hi Sundar,

I think this link should be useful to you.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1bbc91c3-0401-0010-91bc-a25b2a3d...

Just play around with this exercise,am sure you will get some breakthrough.

Regards

<b><i>Raja Sekhar</i></b>