import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class HtmlImageExample { public static void main (String args[]) throws Exception { String host = args[0]; String from = args[1]; String to = args[2]; String file = args[3]; // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", host); // Get session Session session = Session.getDefaultInstance(props, null); // Create the message Message message = new MimeMessage(session); // Fill its headers message.setSubject("Embedded Image"); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Create your new message part // Set the HTML content, be sure it references the attachment // Set the content of the body part // Create a related multi-part to combine the parts // Add body part to multipart // Create part for the image // Fetch the image and associate to part // Add a header to connect to the HTML // Add part to multi-part // Associate multi-part with message // Send message } }