Send mail from JSF page using beans
Solution 1
In very short:
- make a
<h:commandButton action="#{yourBean.send}"
- make a managed bean annotated with
@ManagedBean("yourBean")
that has asend(..)
method - get commons-email and read its short "User guide"; get a working smtp server (commons-email depends on JavaMail, so get that on the classpath as well)
- in the send method use commons-email to send the email
(You should go through a JSF tutorial to see how to gather the form parameters)
Note that java is a bit more complex. "Send mail through JSF" isn't a particularly good question. It consists of two questions:
- how to have a form submitted with JSF (every tutorial explains that)
- how to send email in Java in general
Solution 2
On my practice SEAM Mail really helps in sending mail.
Here you can find a good tutorial on it:
Sending mail from JSF - Seam mail
Dimmy3
Updated on October 26, 2020Comments
-
Dimmy3 over 3 years
i am creating a web application using jsf and primefaces, and my question is how to send an email through site's contact form (i've done this using php before, very easily, but never using jsf). I have created form on contact.xhtml page, as well as bean class to support that, and all that form should do is to send bean's data to a predefined mail (ie. gmail). I have also found several "tutorials" of how to send email using JavaMail, but nothing seems to work properly. The form itself, consists of name, email and message fields.
Can someone write how to do that, or give me a link. I would be very gratefull.
Do i need my site to be running on (online) server, or i can test it from localhost.
Thank you in advance.