MailSender1.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- //JavaMail:MailSender1.java
- //author:ZhangHongbin
- //This program is protected by copyright laws.
- //Mail Sender program.
- import java.util.*;
- import javax.mail.internet.*;
- import javax.mail.*;
- public class MailSender1
- {
- public static void main(String[] args) throws Exception
- {
- String smtp = "smtp.21cn.com";
- String from = "abc@21cn.com";
- String to = "abc@21cn.com";
- Properties props = System.getProperties();
- Session session = Session.getInstance(props,null);
- MimeMessage msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(from));
- msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
- msg.setSubject("Send mail 测试");
- msg.setText(" Test text 测试");
- Transport transport =session.getTransport("smtp");
- transport.connect(smtp,"","");
- transport.sendMessage(msg,msg.getAllRecipients());
- transport.close();
- }
- }