on 11-20-2007 7:59 AM
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
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>]");
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.