利用program send email 不是一件新鮮事. 工作上須要用JAVA+Spring 去做, 在google及研發下, 所得source code 如下.
public boolean sendMail(E) { boolean result=false; try { // Generate Spring MIME message and send. // Get system properties and append to session. Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", "192.168.0.1"); Session session = Session.getDefaultInstance(properties); MimeMessage mimeMessage=new MimeMessage(session); mimeMessage.setFrom(new InternetAddress("[email protected]")); mimeMessage.addRecipient(RecipientType.TO, new InternetAddress("[email protected]")); mimeMessage.setSubject("Test subject"); mimeMessage.setContent("Test content", "text/html; charset=utf-8"); result=true; } catch (Exception ex) { ex.printStackTrace(); } return result; }
Reference
- Java Sending Email, TutorialsPoint
http://www.tutorialspoint.com/java/java_sending_email.htm
Leave a Reply