i am unable to send the mail with the attachment.anybody help me,very urgent
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mahesh_kalluri
Posted On:   Saturday, March 2, 2002 12:33 AM

<%@ page import = "java.io.IOException,java.io.PrintWriter,java.sql.*,java.util.Hashtable,java.util.Properties" %> <%@ page import = "javax.mail.*,javax.mail.internet.InternetAddress,javax.mail.internet.MimeMessage" %> <%@ page import = "javax.servlet.*,javax.servlet.http.*" %> <%@ page import = "javax.mail.BodyPart,javax.activation.*,javax.mail.internet.MimeBodyPart,javax.mail.internet.MimeMultipart" %> <% try { String host = "xxxxxx"; String from = "xxx@xxx.com"; String actto = "yyy@yyy.com"; String pSubject = "see the attachment"; String pMessage = "the    More>>
<%@ page import = "java.io.IOException,java.io.PrintWriter,java.sql.*,java.util.Hashtable,java.util.Properties" %>

<%@ page import = "javax.mail.*,javax.mail.internet.InternetAddress,javax.mail.internet.MimeMessage" %>

<%@ page import = "javax.servlet.*,javax.servlet.http.*" %>

<%@ page import = "javax.mail.BodyPart,javax.activation.*,javax.mail.internet.MimeBodyPart,javax.mail.internet.MimeMultipart" %>

<%
try
{
String host = "xxxxxx";
String from = "xxx@xxx.com";
String actto = "yyy@yyy.com";
String pSubject = "see the attachment";
String pMessage = "the attachement mail is as follows:";

Properties properties = new Properties();
properties.put("mail.smtp.host", host);
properties.put("mail.from", from);

Session session1 = Session.getInstance(properties, null);

Message msg = new MimeMessage(session1);
msg.setFrom(new InternetAddress(from));

InternetAddress[] to=null;
to = InternetAddress.parse(actto);
msg.setRecipients(Message.RecipientType.TO, to);

msg.setSubject( pSubject );
msg.setSentDate(new java.util.Date());

out.println("before mime body");

// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(pMessage);

// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds=new FileDataSource(request.getParameter("filename"));
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(request.getParameter("filename"));

// create the Multipart
//and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);

// add the Multipart to the message
msg.setContent(mp);

out.println("after mime body");

Transport transport = session1.getTransport("smtp");
transport.connect();

out.println("before transport");
transport.send(msg);
out.println("message sent");
}
catch(Exception e)
{
out.println(e.toString());
}
%>

the error i am getting is:
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException: C:WINDOWSDesktopa.txt    <<Less

Re: i am unable to send the mail with the attachment.anybody help me,very urgent

Posted By:   John_Zukowski  
Posted On:   Saturday, March 2, 2002 10:26 PM

Sending mail with attachments is already covered in the FAQ, as is uploading files from client to server. Remember with JSP the JSP file runs on the server, not the client, so in your case C:WindowsDesktopa.txt would be on the server.
About | Sitemap | Contact