public class T {
public static void main(String[] args) throws MessagingException { Properties props=new Properties(); props.put("mail.smtp.host", "smtp.qq.com"); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props); session.setDebug(true); Message msg = new MimeMessage(session); Address from = new InternetAddress("&&&&&@qq.com"); msg.setFrom(from); Address to = new InternetAddress("&&&&&@qq.com"); msg.setRecipient(RecipientType.TO, to); msg.setSubject("sadhnsalkjfnlkdsflsda**title"); msg.setText("neirong"); msg.setSentDate(new Date()); msg.saveChanges(); Transport tran = session.getTransport("smtp"); tran.connect("smtp.qq.com","&&&&&", "*********");//servername**userName**password tran.sendMessage(msg,msg.getAllRecipients()); tran.close(); } } |
|
来自: 闪宁斯达 > 《javax-mail》