import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class AttachExample { public static void main (String args[]) throws Exception { String host = args[0]; String from = args[1]; String to = args[2]; String filename = args[3]; // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", host); // Get session Session session = Session.getInstance(props, null); // Define message // Create the message part // Fill the message // Create a Multipart // Add part one // // Part two is attachment // // Create second body part // Get the attachment // Set the data handler to the attachment // Set the filename // Add part two // Put parts in message // Send the message } }