简单的邮件发送:
public static void main(String[] args) throws UnsupportedEncodingException, AddressException {
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth ", "true");
Session session = Session.getInstance(props, null);
session.setDebug(true);
try {
Transport transport = session.getTransport();
transport.connect("smtp.qq.com", "[email protected]", "888888");
MimeMessage msg = new MimeMessage(session);
msg.setFrom(InternetAddress.parse("\"yonge.gao\"<[email protected]>")[0]);
//msg.setRecipients(Message.RecipientType.TO, "[email protected],[email protected]");
msg.setSubject(MimeUtility.decodeText("第二次实验"));
msg.setSentDate(new Date());
msg.setText("Hello, World!\n");
transport.sendMessage(msg, InternetAddress.parse("[email protected]"));
transport.close();
} catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
}