Having problems in attaching a .txt file.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Muhammad_Shakeel
Posted On:   Monday, April 2, 2001 04:30 PM

I tried to attach a .txt file within a JSP using the following code : <% try{ Properties props = new Properties(); Session sendMailSession; Store store; Transport transport; String pFileName = "cgmail.txt"; sendMailSession = Session.getInstance(props, null); props.put("mail.smtp.host", "localhost"); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress(fromAddress)); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress)); newMessage.setSubject("Message Subject..."); newMessage.setSentDate(new Date());    More>>
			
I tried to attach a .txt file within a JSP using the following code :


<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
String pFileName = "cgmail.txt";

sendMailSession = Session.getInstance(props, null);

props.put("mail.smtp.host", "localhost");

Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(fromAddress));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
newMessage.setSubject("Message Subject...");

newMessage.setSentDate(new Date());

MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msg.toString());
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds=
new FileDataSource(pFileName);
mbp2.setDataHandler(
new DataHandler(fds));
mbp2.setFileName(pFileName);
// create the Multipart
//and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message

newMessage.setContent(mp);


transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>


a "File Not Found" exception occurs at runtime. the file (cgmail.txt) is
present in the same directory as that of JSP file.

Any guidelines....

PS; I actually want to send the contents of cgmail.txt file as mail body.

   <<Less

Re: Having problems in attaching a .txt file.

Posted By:   John_Zukowski  
Posted On:   Tuesday, April 3, 2001 10:00 PM

Keep in mind that the web server doesn't execute the JSP file from the JSP directory, but rather a compiled version of it from a different directory.
About | Sitemap | Contact