cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Email from EJB exposed as Webservice

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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>

Answers (2)

Answers (2)

Former Member
0 Kudos
Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Hanoz,

here what you are searching for, from the official Sun:

http://java.sun.com/developer/EJTechTips/2004/tt0426.html

Regards,

Vito