Java Tomcat Hosting

Account specs

Discover the possibilities

Java Environment Setup

How to guides

Pricing & Ordering

Specials

Order Now

 

 

How to work with
Servlets
Java Development Frameworks
Tomcat & Database
Deploying webapps
JSPs and PHPs
Ecommerce and Java
https through Tomcat

 

   

Domain Search: www.

SERVERS & NETWORK  |  SUPPORT  |  WHY OXXUS  |  TESTIMONIALS  |  ABOUT US  |  CONTACT |  ORDER NOW

 JavaMail


 

Untitled Document

Java Mail Example

Here is example to send emails via Jsp.

There are two files. MailTest.jsp and MailSubmit.jsp

 

#######################Begining of file: MailTest.jsp

<form action="MailSubmit.jsp">

<table>

<tr>
<td>To
<td><input type=text name="to" value=receiver@tralala.com >

<tr>
<td>From
<td><input type=text name="from" value=sender@blabla.com>

<tr>
<td>Subject
<td><textarea rows="10" cols="50" name="subject">Hello,
World</textarea>

<tr>
<td colspan="2"><input type="submit">

</table>

</form>

 

MailTest.jsp MODIFICATIONS


FROM: sender@blabla.com - need to enter YOUR email address where you're sending mail from. The domain must be hosted at our server or it will not work (it can't be email@hotmail.com).
TO: receiver@tralala.com - need to enter receivers email address
SERVER-IP-ADDRESS: enter your servers IP address (info can be found in your activation email)

 

IMPORTANT!
Make sure that you have javamail.jar file in your /var/www/html/WEB-INF/lib/ directory.

 

 

 

 

#######################Beginning of file: MailSubmit.jsp
<%@page import="
java.sql.*,
java.util.*,
java.io.*,
javax.mail.*,
javax.mail.internet.*,
javax.activation.*
"
%>


<%
String host = "216.12.218.215";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");

Properties props = new Properties();
props.setProperty("mail.smtp.host", host);
Session s = Session.getInstance(props, null);
boolean bOkay = false;

try
{
MimeMessage msg = new MimeMessage(s);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(MimeMessage.RecipientType.TO, new
InternetAddress(to));
msg.setSubject(subject);
msg.setText("");
Transport transport = s.getTransport("smtp");
transport.connect();
transport.send(msg);
// Transport.send(msg);
bOkay = true;
}
catch (MessagingException mex)
{
bOkay = false;
response.getWriter().println("<font color=red><b>Error
sending Email:<br>");
response.getWriter().println(mex.getMessage());
response.getWriter().println("</font>");
}

if( bOkay )
response.getWriter().println("<font color=green><b>Email was
sent</font>");

 

 

MailSubmit.jsp MODIFICATIONS


No modifications necessary

 

 

 

 

See also:

Working with Servlets

Working with Tomcat & Database

Running JSPs and PHPs

Java development frameworks

Ecommerce and Java

Deploying webapps

ZERO downtime transfers

 

 

 

 

 

 

 

See list of ALL supported technologies and account features

 

Need further assistance? 

Visit our Java knowledge base or

contact us and we'll be happy to help

 

 



Order with confidence

100% Secure Ordering
Privacy Policy
Money back guarantee

 

Host of choice for 1,500+

Java Developers

 

 Why host with Oxxus
 Customer Testimonials
 Meet the Oxxus Team


Choose your gift
Free domain
Free Unique IP
$$ off hosting fee
Pick your free gift
.........................................

 

It's fast and stable like dedicated server yet it's as affordable as virtual hosting. What is it?

 


 


and go live in just 4hours

 

 

Copyright ® 2003-2007 Oxxus.Net * USA * UK * AUP * Best web hosting solutions from internets leading web hosting provider * Tutorials * Resources * Blog * FAQ
JSP hosting * Java hosting * Servlet hosting * J2EE hosting * Tomcat hosting * PHP hosting * SSL hosting