This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Multiple email attachments" Watch "Multiple email attachments" New topic
Author

Multiple email attachments

ben patrick
Greenhorn

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";
System.getProperties().put("mail.host","company.com");
URL u = new URL("mailto: <" + toAddress + ">");
URLConnection c = u.openConnection();
c.setDoInput(false);
c.setDoOutput(true);
//
System.out.println("Connecting...");
System.out.flush();
c.connect();
PrintWriter out = new PrintWriter(new OutputStreamWriter(c.getOutputStream()));
out.print("From: \"my name\" <name@hotmail.com>\n");
out.print("To: " + toAddress + "\n");
out.print("Subject: files copied to hist\n");
out.print(s + "\n");
out.close();
System.out.println("Message send to "+toAddress);
}
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: SendMail [<mailhost>]");
}
}
//
Ben
[This message has been edited by ben patrick (edited March 06, 2001).]
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
Ben,
See the post http://www.coderanch.com/t/263541/java/java/Java-Mail-Attachments
Here I gave a code for sending attachments using Javamail. For multiple attachments add more bodyparts as required.

Ajan

[ UD: changed URL to the current format ]
[ March 10, 2006: Message edited by: Ulf Dittmer ]
 
GeeCON Prague 2014
 
subject: Multiple email attachments