on 08-22-2007 11:32 AM
Hi,
I have created a EJB, which i have wrapped in an EAR & exposed as a WebService.
<b>I want the code to send an email from the EJB</b>
I know there is a code to send email, but that code is to send an email from WebDynpro. I am not sure if that will work with the EJB.
Any ideas??
Regards,
Hanoz
Hi Hanoz,
you can create a Webservice for email sendings, please follow this usefull and smart weblog:
/people/renald.wittwer/blog/2005/01/05/develop-a-web-service-that-sends-an-email
Then you can call webservice methods from your EJB project in order to send email.
That's all. Hope this help you.
Regards,
Vito
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanx for the prompt response.
I went through that blog. Its good, but it requires me to install additional plugins, which is dont want to do.
Here is the code to send email from WebDynpro:
String l_str_to = "<destination email id>";
String l_str_from = "sender";
String p_subject = "U've got mail!!! ";
// String p_l_request_id = "1" ;
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "<SMTP SERver ip>";
// Create properties, get Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify which host to send it to
props.setProperty("mail.smtp.host", host);
// To see what is going on behind the scene
//props.put("mail.debug", "true");
Session session = Session.getInstance(props);
try {
// Instantiatee a message
Message msg = new MimeMessage(session);
//Set message attributes
msg.setFrom(new InternetAddress(l_str_from));
InternetAddress[] address = { new InternetAddress(l_str_to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(p_subject);
//msg.setSentDate(new Date());
java.util.Date dt = new java.util.Date();
msg.setSentDate(dt);
// Set message content
msg.setText("This is a test email");
//Send the message
Transport.send(msg);
}
catch (Exception mex)
{
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
<b>i want a similar code, which can be executed from the EJB!!!!</b>
Hi,
Try This,
http://help.sap.com/saphelp_nw04/helpdata/en/91/9c2226df76f64fa7783dcaa4534395/content.htm
Regards
Nandha.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This looks like standard java mail API from SUN...
try this link
http://www.codeproject.com/useritems/Java_Mail.asp
you only need the jars on the classpath
bye
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hanoz,
here what you are searching for, from the official Sun:
http://java.sun.com/developer/EJTechTips/2004/tt0426.html
Regards,
Vito
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
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.