MailSender1.java
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. //JavaMail:MailSender1.java
  2. //author:ZhangHongbin 
  3. //This program is protected by copyright laws.
  4. //Mail Sender program.
  5. import java.util.*;
  6. import javax.mail.internet.*;
  7. import javax.mail.*;
  8. public class MailSender1
  9. {
  10. public static void main(String[] args) throws Exception
  11. {
  12. String smtp = "smtp.21cn.com";
  13. String from = "abc@21cn.com";
  14. String to = "abc@21cn.com";
  15. Properties props = System.getProperties();
  16. Session session = Session.getInstance(props,null);
  17. MimeMessage msg = new MimeMessage(session);
  18. msg.setFrom(new InternetAddress(from));
  19. msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  20. msg.setSubject("Send mail 测试");
  21. msg.setText(" Test text 测试");
  22. Transport transport =session.getTransport("smtp");
  23. transport.connect(smtp,"","");
  24. transport.sendMessage(msg,msg.getAllRecipients());
  25. transport.close();
  26.     }
  27. }