Parent Category: Java EE Tips
Category: JavaServer Pages
JSP service may be used to send mail messages. For this first example we will create a simple JSP that
sends an email. In order to send mail the application should have JavaMail and JAF packages in its class path.
This example uses hardcoded value for source and recipient address, but it could be easilly changed
to a HTML form input.
You can use your own email address so that you may check for the sent mail. You should also replace the "smtp.mail.example.com" value with your own SMTP email server:
Properties props = new Properties();
Session s = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(s);
message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");
A Message has been sent. <br>
Check your inbox.
<a href="sendmail.jsp">Click here to send another!</a>