Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple email attachments

 
ben patrick
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic