cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Mail with attachment from WD

mathias_lange3
Explorer
0 Kudos

Hi all,

I wan't to send an email from webdynpro with an attached pdf-document. I had a look at Tutorial 31, but i will only use the first part, sending email with attached interactive form. So I decided to build a new project. I did everything as in the tutorial described, but when entering the following code into the wdDoInit method from the SendView an error occurs.

//@@begin wdDoInit()

// @TODO Enter your email address for the setFrom and setTo methods by replacing the text in angle brackets.

wdContext.currentEmailElement().setFrom("name@company.com");

wdContext.currentEmailElement().setTo("name@company.com");

wdContext.currentEmailElement().setCc("");

wdContext.currentEmailElement().setBcc("");

wdContext.currentEmailElement().setSubject("Travel Request Form");

wdContext.currentEmailElement().setBody("BlaBlaBla");

//@@end

In the coding is no error. In the Context node of the SendView I created a new value node with the value attributes. When writing the code and using strg+space i can complete automatically, so no writing errors.

When deploying and running the application I get always a NullPointerException, if make no difference if i delete one entry or which line of code i insert, the same error.

java.lang.NullPointerException

at com.ao.test.emailtest.SendView.wdDoInit(SendView.java:99)

at com.ao.test.emailtest.wdp.InternalSendView.wdDoInit(InternalSendView.java:127)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit(DelegatingView.java:61)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

at com.sap.tc.webdynpro.progmodel.view.View.initController(View.java:274)

at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:200)

I've compared my project with the one from tutorial but i found no differences.

Have anybody have an idea what to do?

Thanks

Mathias

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

NullpOinter excepttion could be bcose of "currentEmailElement()".

Please create an element of EmailNode before these statements.

IPrivate<ViewName>.IEmailElement ele=wdContext.createEmailElement();

wdContext.NodeEmail().addElement(ele);

You can use the following for sending attachments :

BodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(Attachment);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(Attachment);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName(Attachment);

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

Regards, Anilkumar

Message was edited by: Anilkumar Vippagunta

Former Member
0 Kudos

Hi mathias,

you can also switch the cardinality of your email node from 0:n to 1:n. Thus, you will alsways have one element in the node and avoid NullPointer B-]

kesap

mathias_lange3
Explorer
0 Kudos

Hi,

many thanks to both of you. I Have just send a mail! Couldn't believe sending a mail makes so happy!

Answers (0)