This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX 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 ]
I agree. Here's the link:
subject: Multiple email attachments
It's not a secret anymore!