• java群发邮箱


    package com.hans.email;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Properties;

    import javax.mail.Address;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class Email extends HttpServlet{

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub


    }
    public static void main(String[] args) {
    try {
    //request.setCharacterEncoding("utf-8");//设置字符编码
    //response.setCharacterEncoding("utf-8");
    //System.out.println(6);
    //接收前端数据
    String name="wuyunhuiv587@163.com,3385351592@qq.com,2673629310@qq.com,184867747@qq.com";

    String top="你好";

    String tile="最近过的怎么,有";

    String username="2694072078@qq.com";
    String pass="bmmhpqtkvilhdeca";
    //bmmhpqtkvilhdeca
    //邮箱发送
    Properties pr=new Properties();

    pr.put("mail.transprot.protocol", "smtp");
    pr.put("mail.smtp.port", 587);
    pr.put("mail.host", "smtp.qq.com");

    pr.setProperty("mail.transport.protocol", "smtp");
    pr.put("mail.smtp.auth", true);
    //创建邮箱
    Session session=Session.getInstance(pr);

    MimeMessage ms=new MimeMessage(session);
    //邮箱来源
    Address toAddress;
    toAddress=new InternetAddress(username);

    ms.setFrom(toAddress);
    //邮箱接受者
    ms.addRecipients(Message.RecipientType.TO, name);
    ms.setSubject(top);
    ms.setText(tile);
    ms.saveChanges();//保存


    Transport tr=session.getTransport();
    tr.connect(username, pass);
    tr.sendMessage(ms, ms.getAllRecipients());

    //PrintWriter pw=response.getWriter();
    /*pw.print("");
    pw.close();*/
    System.out.println("发送成功");

    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    }

    需要这三个jar

    javax.activation.jar
    javax.mail.jar
    smtp-1.4.jar

  • 相关阅读:
    查看whl包名是否满足系统的条件的命令,以此解决whl包出现“is not a supported wheel on this platform”错误提示的问题
    C++-文件输入输出流
    C++-PTA-6-7-1 地下迷宫探索
    C++-PTA-时钟模拟
    数据结构-深入虎穴-树的应用
    数据结构-二叉树-(先序|后序)+中序求(后序|先序)笔记
    C++-课后习题-日期类DATE时间类Time
    C++-课后习题-学生类
    数据结构-串数组广义表笔记
    数据结构-PTA-银行业务队列简单模拟
  • 原文地址:https://www.cnblogs.com/nancheng/p/9008346.html
Copyright © 2020-2023  润新知