import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailTransfor {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
// 要使用用户名,密码进行认证登录,如果是直接给smtp服务器发就不用这个了
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props);
session.setDebug(true);
String str = "是我做得不好";
Message message = new MimeMessage(session);
message.setText(str);
message.setSubject("对不起");
message.setFrom(new InternetAddress("26664141@qq.com", "黄彪"));
Transport transport = session.getTransport(); // transport的一些信息保存在session里
transport.connect("smtp.qq.com", 25, "26664141", "password");
transport.sendMessage(message, InternetAddress.parse("biao.mac@gmail.com"));
transport.close();
}
}