Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 22nd, 2006, 01:50 AM
Registered User
Join Date: Apr 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Sending Email

    I want a to write jsp code which can send emails to multiple recipients with attachment.i had used the follwing code.but the problem with the following code it can supports single recipient and it is unable to send the email body but the attachemnt can send.

<%@ page import=" javax.activation.*, java.util.*, java.io.*, javax.mail.internet.*, javax.mail.* " %>

<title>Send an email ans File with jsp page</title>
<body bgcolor="#C0C0C0" text="#CC0000" >


if(request.getMethod().equals("POST") )
  boolean status = true;

  // enter here the smtp mail server address
  // ask your ISP to get the proper name
  String mailServer = "mail.nannacomputers.com";

  String fromEmail = request.getParameter("from");
  String toEmail = request.getParameter("to");
  String messageEnter = request.getParameter("message");
  String fileName = request.getParameter("theFile");


    Properties props = new Properties();
    props.put("mail.smtp.host", mailServer);
    Session s = Session.getInstance(props,null);
    MimeMessage message = new MimeMessage(s);
    InternetAddress from = new InternetAddress(fromEmail);
    InternetAddress to = new InternetAddress(toEmail);
    message.addRecipient(Message.RecipientType.TO, to);
    message.setSubject("Send Email with jsp");

    // Create the message part
    BodyPart messageBodyPart = new MimeBodyPart();

    // Fill the message
       // Part two is attachment
    Multipart multipart = new MimeMultipart();
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(fileName);
    messageBodyPart.setDataHandler(new DataHandler(source));

   // Put parts in message

 // ENCTYPE="multipart/form-data"


  catch (Exception e)
     System.out.println(e.getMessage() );
     out.println("ERROR, your message failed, reason is: " + e);
     status = false;


  if (status == true)
     out.println("Your message to " + toEmail + " was sent successfully!");

<h1>Send email and attatchment file with jsp</h1>
<form method="post" name="mail" action="mailer.jsp">
<table BORDER="0">
    <td>To :</td>
    <td><input type="text" name="to" size=24></td>


    <td>From :</td>
    <td><input type="text" name="from" size=24></td>


    <td>Message :</td>
    <td><TEXTAREA name="message" ROWS = "5" COLS="65"></TEXTAREA></td>


    <td>File attachment: </td>
    <td><input TYPE="FILE" name="theFile"></td>

     <td><input TYPE="submit" value="submit" name="Command"></td>






Please provide the solution ASAP


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Email Sending Problem dharmeshtandel Forum and Wrox.com Feedback 1 April 30th, 2008 08:46 AM
Email sending problem aneesh_sunu@yahoo.co.in ASP.NET 1.0 and 1.1 Basics 3 December 21st, 2006 01:16 PM
problem sending an email leo_vinay SQL Server 2000 3 July 23rd, 2006 12:55 PM
Email Sending Problem.. gaurav_jain2403 VB.NET 2002/2003 Basics 2 February 4th, 2006 09:08 AM
sending email problem maitias C# 1 February 3rd, 2006 01:11 PM

All times are GMT -4. The time now is 06:08 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.