aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending file as an attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending file as an attachment" Watch "Sending file as an attachment" New topic
Author

Sending file as an attachment

madhavi prasad
Greenhorn

Joined: Jul 29, 2004
Posts: 17
Hi all,

Im new to JAVA Mail . My requirement is i need to send a file as an attachment can any one give me any references to links, r sample code.

Thnx in advace


madhaviprasad
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
Have alook at this


try
{
String host="192.168.1.83";
String to=request.getParameter("to");
String from=request.getParameter("from");
String sub=request.getParameter("sub");
String matter=request.getParameter("matter");
String filename=request.getParameter("F1");

boolean sessionDebug=false;

Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg=new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(sub);
msg.setSentDate(new Date());
msg.setText(matter);


BodyPart bp=new MimeBodyPart();
bp.setText(matter);
Multipart multipart=new MimeMultipart();
multipart.addBodyPart(bp);

BodyPart msgpart=new MimeBodyPart();
DataSource source=new FileDataSource(filename);
msgpart.setDataHandler(new DataHandler(source));
msgpart.setFileName(filename);
multipart.addBodyPart(msgpart);
msg.setContent(multipart);

Transport.send(msg);

out.println("Mail was successfully sent to"+to);
out.println("from"+from);
out.println("using host"+".");

}
catch(Exception e)
{
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Moved to Other Java APIs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
payal agrawal
Ranch Hand

Joined: Oct 11, 2005
Posts: 44
Look at the URL below:

How to send an email with a file attachment
http://www.java-tips.org/content/view/616/29/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending file as an attachment