Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 24th, 2006, 01:07 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in sending Email

Hi,
    I want 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.* " %>

<html>
<head>
<title>Send an email ans File with jsp page</title>
</head>
<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");


try
  {

    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);
    message.setFrom(from);
    InternetAddress to = new InternetAddress(toEmail);
    message.addRecipient(Message.RecipientType.TO, to);
    message.setSubject("Send Email with jsp");
    //message.setText(messageEnter);

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

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

   // Put parts in message
   message.setContent(multipart);

   Transport.send(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!");
  }
}
else
{
%>

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

<p>

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

<p>

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

<p>

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

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


</table>



</form>

<%
}
%>

</body>



</html>



Please provide the solution ASAP

Regards...
Rama

Reply With Quote
Reply


Thread Tools
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 09: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 01: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 12:13 AM.


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