Here is the code to send an attachment:
import java
import javax
import javax
import javax
public static void main (String args[])
throws Exception {
String host = args[
String from = args[
String to = args[
String fileAttachment = args[
// Get system properties
Properties props = System
// Setup mail server
props
// Get session
Session session =
Session
// Define message
MimeMessage message =
new MimeMessage(session);
message
new InternetAddress(from));
message
Message
new InternetAddress(to));
message
// create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart();
//fill message
messageBodyPart
Multipart multipart = new MimeMultipart();
multipart
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart
new DataHandler(source));
messageBodyPart
multipart
// Put parts in message
message
// Send the message
Transport
}
}
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25330.html