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.
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 EmailAction.java
import javax.ejb.Local;
@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;
@Stateful
@Name("email")
public class EmailAction implements Email
{
@In(create=true)
private org.jboss.seam.faces.Renderer renderer;
@Logger private Log log;
public void send() {
try {
renderer.render("/samplemail.xhtml");
log.info("email sent to asker");
}catch (Exception e) {
e.printStackTrace();
log.info("Error while sending the mail");
}
}
@Remove
@Destroy
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:
Post a Comment