In this tutorial I would like to describe how to send mail from your jsf contact form.
There are a lot of solutions to this problem. But on my practice I really liked SEAM Mail.
There are a few things you have to do.
1. Download Seam libraries
2. Add seam-beans.xml to your WEB-INF folder of your project with the following content:
3. Use the following to send mail:
There are a lot of solutions to this problem. But on my practice I really liked SEAM Mail.
There are a few things you have to do.
1. Download Seam libraries
2. Add seam-beans.xml to your WEB-INF folder of your project with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="urn:java:ee" xmlns:mail="urn:java:org.jboss.seam.mail.core"
xmlns:ss="urn:java:org.jboss.seam.security" xmlns:ee="urn:java:ee"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
<mail:MailConfig serverHost="yoursmtpserveripaddress" serverPort="25">
</beans>
3. Use the following to send mail:
package org.netlink.view.registration;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Instance;
import javax.inject.*;
import org.jboss.seam.mail.api.*;
import org.jboss.seam.mail.core.enumerations.MessagePriority;
public class MailAction implements Serializable {
@Inject
private Instance<MailMessage> mailMessage;
public void sendMail() {
MailMessage m = mailMessage.get();
m.from("John Doe<customer@mysite.com>")
.to("Jane Doe<admin@ mysite.com >")
.subject(subject)
.bodyHtml(body)
.importance(MessagePriority.HIGH)
.send();
}
}
Now use sendMail() method where ever you want.
Best regards,
Netlink community member
Комментариев нет:
Отправить комментарий