[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I send email from JSP?

Posted on 2004-09-08
5
Medium Priority
?
416 Views
Last Modified: 2010-04-01
I have JSP running on Unix, and I want to send emails to customers.  
Can someone help with sample code?
0
Comment
Question by:g118481
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 12006500
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 12006506
If you are familiar with taglib, this is an easier option for you

http://jakarta.apache.org/taglibs/doc/mailer-doc/intro.html

Hope this help
0
 

Expert Comment

by:kheefatt
ID: 12006956
Sorry in a hurry. I will paste to u some sample codes tomorrow morning..8 hrs from now. Check back!
0
 

Accepted Solution

by:
kheefatt earned 400 total points
ID: 12012647
mail_form.html
------------------

<html>
<head>
</head>
<%@ page language="java" import="java.sql.*, java.util.ArrayList" %>
<body>
<form name="SubForm" method="post" action="send_mail.jsp">
      <table width="50%" border="1" >
      <tr>
            <td width="108" height="34">To : </td>
            <td width="363">
            <input type="text" name="receiver">
            </td>
      </tr>
      <tr>
            <td height="80" >Message : </td>
            <td><textarea name="mailtext"></textarea>
            </td>
      </tr>
      <tr>
            <td height="34" valign="top">&nbsp;</td>
            <td valign="top"><input type="submit" name="submit" value="Submit Information">
            </td>
      </tr>
      </table>
</form>
</body>
</html>

send_mail.jsp
----------------

<%@ page language="java" import="java.sql.*, java.util.ArrayList" %>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<html>
<head>
</head>
<body>
<table width="50%" border="0" >
<tr>
<td>
<%
      String emailAdd = request.getParameter("receiver");
      String mailBody = request.getParameter("mailtext");
      boolean mail_error = false;
      String errMsg = "";

      try
      {
            Properties props = new Properties();
            props.put("mail.smtp.host", "127.0.0.1");  //replace 127.0.0.1 with the name u specify in your mail server
            Session s = Session.getInstance(props,null);
            MimeMessage message = new MimeMessage(s);
            InternetAddress from = new InternetAddress(emailAdd);
            message.setFrom(from);
            InternetAddress to = new InternetAddress("kheefatt@yahoo.com"); //your email address
            message.addRecipient(Message.RecipientType.TO, to);
            message.setSubject("Mail Test!");
            message.setText(mailBody);
            Transport.send(message);
      }
      catch (Exception ex)
      {
            String titleMsg = "Error Exception";
            errMsg = ex.getMessage();
            mail_error = true;
      }      
      if (mail_error==false)
            out.write("Thank you for subscribing to our newsletter.<BR>");
      else if (mail_error==true)
      {
            out.write("There's an error in the mail server. Please try again later!<BR>\n");
      }
%>
</td>
</tr>
</table>
</body>
</html>

Remember that you need a mail server. You can one free here. The mail server must be running when executing this mail function! All the best to you!

http://www.softrom.net/download_12082.html
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 12016304
good sample kheefatt. :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question