The example requires two packages: Mail.jar and Activation.jar, whose download address is:
Http://java.sun.com/products/javamail/downloads/index.html
Http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html
Unzip after downloading, place Mail.jar and Activation.jar in the Lib folder in project, configure the environment variable for it, or add it to "libraries" in MyEclipse in "Java build Path".
Project has three classes: the Entry Class (Testjavamail), the Mail information Class (Mailbean), and the Send Message Class (SendMail)
Mailbean.java package test3;
Import Java.util.Vector;
public class Mailbean ... {
Private String to; Recipient
Private String from; Sender
Private String host; SMTP Host
Private String username; Sender's user name
private String password; Sender's password
Private String subject; Message subject
Private String content; Message body
vector<string> file; Multiple attachments
private String filename; File name of attachment
Public String Getto () ... {
return to;
}
public void Setto (String to) ... {
This.to = to;
}
Public String getfrom () ... {
return from;
}
public void Setfrom (String from) ... {
This.from = from;
}
Public String gethost () ... {
return host;
}
public void Sethost (String host) ... {
This.host = host;
}
Public String getusername () ... {
return username;
}
public void Setusername (String username) ... {
This.username = Username;
}
Public String GetPassword () ... {
return password;
}
public void SetPassword (String password) ... {
This.password = password;
}
Public String getsubject () ... {
return subject;
}
public void Setsubject (String subject) ... {
This.subject