就算是一个非常简陋的客户端吧。用163.com发送邮件
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendEmail
{
public static void main(String [] args)
{
// Recipient's email ID needs to be mentioned.
//String to = "liulixin.org@gmail.com";
String to = "18802930979@qq.com";
//往谷歌邮箱发可以,往qq邮箱被退回
//第二次往qq发可以了
// Sender's email ID needs to be mentioned
String from = "liulixin63@163.com";
// Assuming you are sending email from localhost
String host = "smtp.163.com";
// Get system properties
Properties properties = new Properties();
// Setup mail server
properties.put("mail.transpost.protocol","smtp");
properties.put("mail.smtp.host", "smtp.163.com");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port","25");
//properties.put("mail.user", "bGl1bGl4aW42Mw==");
//properties.put("mail.password", "*********");
MailAuthenticator authenticator = new MailAuthenticator("liulixin63", "******");
// Get the default Session object.
Session session = Session.getInstance(properties, authenticator);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Now set the actual message
message.setText("This is actual message");
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MailAuthenticator extends Authenticator {
private String username;
private String password;
public MailAuthenticator(String username, String password) {
this.username = username;
this.password = password;
}
String getPassword() {
return password;
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public void setUsername(String username) {
this.username = username;
}
}
函库源代码:http://pan.baidu.com/share/link?shareid=431484&uk=3878681452
参考:http://188029.net/java/j12-04-01u.html