Wednesday, December 10, 2008

How to Integrate Seam2.0 with GMail SMTP to Send Mails.

Step 1.

For Setting Up the GMail SMTP for the Seam mail Functionality First of All Set the SMTP details in the mail-service.xml in the JBoss\server\default\deploy Folder.
Create on Mail Template File As Follows.
Also Add the property mail.smtp.auth

property name="mail.smtp.auth" value="true" in the properties File.

Step 2:

Set this Configuration File Entry in Components.xml file as follows.
Comment the Existing Session !-- mail:mail-session host="localhost" port="2525" username="test" password="test" --

And teh new Entry will be as follows.
mail:mail-session session-jndi-name="java:/Mail"/

Step 3.

Create an XHTML FIle With Mail Format as follows like Simplemail.xhtml

Step 4:

Create an Session Bean to handle the Request and Send the mail.Named
import javax.ejb.Local;

public interface Email{
public void send();
public void destroy();

import javax.ejb.Remove;
import javax.ejb.Stateful;

import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;
public class EmailAction implements Email
    private org.jboss.seam.faces.Renderer renderer;
    @Logger private Log log;
    public void send() {
      try {
         renderer.render("/samplemail.xhtml");"email sent to asker");
     }catch (Exception e) {
         e.printStackTrace();"Error while sending the mail");

    public void destroy() {}

Call this send method from any of the JSF Command Button as follows.
h:commandLink value="Send Mail to Asker" action="#{email.send}"/.

No comments: