码迷,mamicode.com
首页 > 编程语言 > 详细

java mail发送邮件demo 代码

时间:2014-06-10 10:15:07      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:c   class   java   a   http   ext   

java mail发送邮件demo,引入mail.jar,运行测试发送ok
[代码][Java]代码     
01
import java.util.Date;
02
import java.util.Properties;
03

04
import javax.mail.Authenticator;
05
import javax.mail.Message;
06
import javax.mail.MessagingException;
07
import javax.mail.PasswordAuthentication;
08
import javax.mail.Session;
09
import javax.mail.Transport;
10
import javax.mail.internet.MimeMessage;
11

12
public class MailTest2 {
13

14
    static Authenticator auth = new Authenticator() {
15

16
        @Override
17
        protected PasswordAuthentication getPasswordAuthentication() {
18
            return new PasswordAuthentication("906985170@qq.com", "fuck");
19
        }
20

21
    };
22

23
    public static void main(String[] args) {
24

25
        Properties props = new Properties();
26
        props.put("mail.smtp.host", "smtp.qq.com");
27
        props.put("mail.smtp.auth", "true");
28
        props.put("mail.from", "906985170@qq.com");
29
        Session session = Session.getInstance(props, auth);
30
        try {
31
            MimeMessage msg = new MimeMessage(session);
32
            msg.setFrom();
33
            msg.setRecipients(Message.RecipientType.TO, "tong695@163.com");
34
            msg.setSubject("JavaMail hello world example");
35
            msg.setSentDate(new Date());
36
            msg.setText("Hello, world!\n");
37
            Transport.send(msg);
38
        } catch (MessagingException mex) {
39
            System.out.println("send failed, exception: " + mex);
40
        }
41

42
    }
43
}
导航菜单CSS文章来源:http://www.huiyi8.com/daohang/css/

java mail发送邮件demo 代码,布布扣,bubuko.com

java mail发送邮件demo 代码

标签:c   class   java   a   http   ext   

原文地址:http://www.cnblogs.com/xrkbgan/p/3778290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!