java发送qq邮件

Posted 红狗<葬爱>贼公子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java发送qq邮件相关的知识,希望对你有一定的参考价值。

技术分享

1.需要一个额外的jar::https://java.net/projects/javamail/pages/Home
 下载javax.mail.jar包

2.对发送的账号开启SMTP------并获取授权码----

3.这段代码已通过:----我的授权改了,不要用

 1 /**
 2  * 
 3  */
 4 package com.breaver.bean;
 5 
 6 import java.util.Properties;
 7 
 8 import javax.mail.Message;
 9 import javax.mail.Message.RecipientType;
10 import javax.mail.MessagingException;
11 import javax.mail.Session;
12 import javax.mail.Transport;
13 import javax.mail.internet.AddressException;
14 import javax.mail.internet.InternetAddress;
15 import javax.mail.internet.MimeMessage;
16 
17 import com.sun.org.glassfish.external.probe.provider.annotations.ProbeProvider;
18 
19 /**
20  * @author zzf
21  *
22  */
23 public class Sendmail1 {
24     
25     /**
26      * @param args
27      */
28     public static void main(String[] args)throws AddressException,MessagingException {
29         // TODO Auto-generated method stub
30         Properties properties = new Properties();
31         properties.put("mail.transport.protocol", "smtp");
32         properties.put("mail.smtp.host", "smtp.qq.com");
33         properties.put("mail.smtp.port", "465");
34         properties.put("mail.smtp.auth", "true");
35         properties.put("mail.smtp.ssl.enable", "true");
36         properties.put("mail.debug", "true");
37         
38         Session session = Session.getInstance(properties);
39         Message message = new MimeMessage(session);
40         message.setFrom(new InternetAddress("[email protected]"));
41         message.setRecipients(RecipientType.TO, new InternetAddress[]{
42                 new InternetAddress("[email protected]")});
43         message.setSubject("title");
44         message.setText("hello world");
45         Transport transport = session.getTransport();
46         transport.connect("[email protected]", "asassasasas");
47         transport.sendMessage(message,message.getAllRecipients());
48     }
49 
50 }

 


以上是关于java发送qq邮件的主要内容,如果未能解决你的问题,请参考以下文章

java发送qq邮件

JAVA 使用qq邮箱发送邮件

Java发送QQ邮件-附jar包下载链接

java实现qq邮箱每天定时发送邮件

基于java mail实现简单的QQ邮箱发送邮件

java实现邮件发送验证码