Knowledgebase: Java/JSP Hosting Plans
How do I send email from my servlet or java server pages?
Posted by Customer Service on 03 August 2005 01:51 PM
Please use JavaMail package. Please check the following code:
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
String Fr = "firstname.lastname@example.org";
String To = "email@example.com";
String SMTPhost = "localhost";
Properties props = new Properties();
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress(Fr);
InternetAddress to = new InternetAddress(To);
message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");
<p align="center">A Message has been sent.<br>Check your inbox.</p>
<p align="center"><a href="sendmail.jsp">Click here to send another!</a></p>
Here are some linksÂ for API documentation and short JavaMAil tutorial:
Please note, it's important to use 'localhost' as SMTP host without any
authentication, in any application of any kind on your server. As all other
ways are blocked by us, to prevent spam and uncontrolled mass email sending.
If you have any further questions, please don't hesitate to submit a trouble ticket.