cancel
Showing results for 
Search instead for 
Did you mean: 

How to send mail from Web Dynpro

Former Member
0 Kudos

Hi Experts,

How to send mail from Web Dynpro application?

Can any one help me regarding this?

I am expecting your response.

Thanks in Advance.

Regards,

P.J.Balaji

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

import java.io.*;

import java.net.*;

/**

  • This program sends e-mail using a mailto: URL

**/

public void sendMail() {

try {

// If the user specified a mailhost, tell the system about it.

if (args.length >= 1) System.getProperties().put("mail.host", "<Your Mail Host>);

// Ask the user for the from, to, and subject lines

String from = // get the value from the context attribute that contains from

String to = // get the value from the context attribute that contains to

String subject = "Test Mail from WD"

// Establish a network connection for sending mail

URL u = new URL("mailto:" + to); // Create a mailto: URL

URLConnection c = u.openConnection(); // Create a URLConnection for it

c.setDoInput(false); // Specify no input from this URL

c.setDoOutput(true); // Specify we'll do output

System.out.println("Connecting..."); // Tell the user what's happening

System.out.flush(); // Tell them right now

c.connect(); // Connect to mail host

PrintWriter out = // Get output stream to mail host

new PrintWriter(new OutputStreamWriter(c.getOutputStream()));

// Write out mail headers. Don't let users fake the From address

out.println("From: \"" + from + "\" <" +

System.getProperty("user.name") + "@" +

InetAddress.getLocalHost().getHostName() + ">");

out.println("To: " + to);

out.println("Subject: " + subject);

out.println(); // blank line to end the list of headers

String line = // get teh content from the context attribute

// Close the stream to terminate the message

out.close();

// Tell the user it was successfully sent.

wdComponentAPi.getMessageManager.reportSuccess("Message sent.");

}

catch (Exception e) { // Handle any exceptions, print error message.

System.err.println(e);

System.err.println("Usage: java SendMail [<mailhost>]");

}

}

Former Member
0 Kudos