Java – use beans to send mail from JSF pages

I am using JSF and primefaces to create a web application. My problem is how to send e-mail through the contact form of the website (I used to do this in PHP, which is easy, but I never used JSF) I'm in contact The form is created on the XHTML page and the bean class supporting the form. All forms should send the bean data to the predefined mail (Gmail) I also found several "tutorials" on how to use JavaMail to send e - mail, but nothing seems to work properly The form itself consists of name, email and message fields

Someone can write how to do this, or give me a link I would appreciate it very much

Do I need to run my site on the (online) server, or can I test it from localhost

Thank you first

Solution

Very brief:

>Make a < H: CommandButton action = "#{yourbean. Send}" > with send (..) Annotate managed beans with @ managedbean ("yourbean") of method > get commons email and read its short "user's Guide"; Get a working SMTP server (commons email depends on JavaMail, so you can do the same on the classpath) > send email using commons email in the send method

(you should learn how to collect form parameters through the JSF tutorial)

Note that Java is a bit complex "Sending mail through JSF" is not a particularly good problem It contains two questions:

>How to submit forms using JSF (each tutorial explains this) > how to send e-mail in Java in general

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>