zoukankan      html  css  js  c++  java
  • java发送qq邮件

    来源:qq zone

    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("1147057783@qq.com"));
    41         message.setRecipients(RecipientType.TO, new InternetAddress[]{
    42                 new InternetAddress("3453539748@qq.com")});
    43         message.setSubject("title");
    44         message.setText("hello world");
    45         Transport transport = session.getTransport();
    46         transport.connect("1147057783@qq.com", "asassasasas");
    47         transport.sendMessage(message,message.getAllRecipients());
    48     }
    49 
    50 }
  • 相关阅读:
    【VUE】父子组件通信
    【mysql】密码重设
    Joomla 3.2.0
    浅谈内网渗透
    使用Fiddler的X5S插件查找XSS漏洞
    Asp文件锁定脚本
    php内网探测脚本&简单代理访问
    Linux关闭休眠和屏保模式
    不重启修改计算机名【批处理】
    mimikatz不反弹读取密码
  • 原文地址:https://www.cnblogs.com/zeigongzi/p/6821086.html
Copyright © 2011-2022 走看看