随笔-348  评论-598  文章-0  trackbacks-0
import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

public class SimpleMailTest {
    
    
private static final String TO = "tigertian@gmail.com";
    
    
private static final String TEXT = "Hello World!";
    
    
public static void main(String[] args) throws MessagingException {
        Properties prop
=new Properties();
        prop.setProperty(
"mail.smtp.auth""true");
        prop.setProperty(
"mail.smtp.timeout""25000");
        prop.setProperty(
"mail.smtp.starttls.enable""true");
        prop.setProperty(
"mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
        prop.setProperty(
"mail.smtp.socketFactory.fallback""false");
/*        props.setProperty("mail.smtp.host", "smtp.gmail.com");
        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", "465");
        props.setProperty("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.auth", "true");
*/

        JavaMailSenderImpl jms
=new JavaMailSenderImpl();
        jms.setJavaMailProperties(prop);
        jms.setHost(
"smtp.gmail.com");
        jms.setPort(
465);
        jms.setUsername(
"username");
        jms.setPassword(
"password");
        
        MimeMessage mail
=jms.createMimeMessage();
        MimeMessageHelper helper
=new MimeMessageHelper(mail,true);
        
        helper.setSubject(TEXT
);
        helper.setText(TEXT
);
        helper.setTo(TO
);
        
        jms.send(mail);
        System.out.println(
"Successfully!");
        
        
    }

}
Study Java写的带配置文件的版本
http://www.blogjava.net/ronghai/archive/2007/05/23/119480.html

---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2007-05-30 12:01 TiGERTiAN 阅读(1027) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: