File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Multiple email attachments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Multiple email attachments" Watch "Multiple email attachments" New topic

Multiple email attachments

ben patrick

Joined: Mar 06, 2001
Posts: 1
How do I attach multiple files to an email using a java
application. I'm able to send emails to multiple people and the file names but not the actual files. Any help would be appreciated thanks
here is part of my code
// mailCopy method
public static void mailCopy(String s, String[] emailAddress) {
for (int emailCount = 0; emailCount < emailAddress.length; emailCount++) {
sendEmail(s, emailAddress[emailCount]);
// SendEmail method
public static void sendEmail(String s, String toAddress) {
try {
String boundary = "DataSeparatorString";
URL u = new URL("mailto: <" + toAddress + ">");
URLConnection c = u.openConnection();
PrintWriter out = new PrintWriter(new OutputStreamWriter(c.getOutputStream()));
out.print("From: \"my name\" <>\n");
out.print("To: " + toAddress + "\n");
out.print("Subject: files copied to hist\n");
out.print(s + "\n");
System.out.println("Message send to "+toAddress);
catch (Exception e) {
System.err.println("Usage: SendMail [<mailhost>]");
[This message has been edited by ben patrick (edited March 06, 2001).]
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
See the post
Here I gave a code for sending attachments using Javamail. For multiple attachments add more bodyparts as required.


[ UD: changed URL to the current format ]
[ March 10, 2006: Message edited by: Ulf Dittmer ]
wood burning stoves
subject: Multiple email attachments
Similar Threads
Code to send subject & CC in mail system
SHA1 digest error for javax/mail/MessagingException
Pesudo coding
Sending mail
JavaMail won't send mail