Giter VIP home page Giter VIP logo

jmail's Introduction

介绍

jmail用于发邮件

依赖

javax.mail >=1.6.2

如何使用

  • pom.xml中添加依赖
<dependency>
    <groupId>io.github.topicstudy</groupId>
    <artifactId>jmail</artifactId>
    <version>RELEASE</version>
</dependency>
  • 示例-发简单邮件

    简单邮件:邮件内容只有文本,80%的发邮件需求都是发这种邮件

// 发件人
MailSender sender = new MailSender();
sender.setMailAddress(new MailAddress("[email protected]", "搜狐测试发送者"));//TODO
sender.setPwd("ABCDQAZRTY");//TODO
sender.setSmtp("smtp.sohu.com");
sender.setSmtpPort(25);

// 收件人
List<MailAddress> recipientList = new ArrayList();
recipientList.add(new MailAddress("[email protected]", "接收者3493"));//TODO
recipientList.add(new MailAddress("[email protected]", "接收者163"));//TODO

Mail mail = new Mail();
mail.setSender(sender);
mail.setRecipientList(recipientList);
mail.setSubject("搜狐测试主题-简单邮件");
mail.setHtml("【新浪】验证码是1234,不可告诉任何人!");

 MailUtil.send(mail);
  • 示例-发完整邮件

    完整邮件:邮件内容有文本、图片和附件,即邮件内容结构是完整的

    // 发送
    MailUtil.send(createCompleteMail());
    
    
    /**
     * 创建完整邮件
     */
    private Mail createCompleteMail() {
        String pathPrefix = "src/test/resources/";
        
        // 发件人
        MailSender sender = new MailSender();
        sender.setMailAddress(new MailAddress("[email protected]", "搜狐测试发送者"));//TODO
        sender.setPwd("ABCDQAZRTY");//TODO
        sender.setSmtp("smtp.sohu.com");
        sender.setSmtpPort(25);
    
        // 收件人
        List<MailAddress> recipientList = new ArrayList();
        recipientList.add(new MailAddress("[email protected]", "接收者3493"));//TODO
        recipientList.add(new MailAddress("[email protected]", "接收者163"));//TODO
    
        // 内嵌图片
        List<File> pics = new ArrayList();
        pics.add(new File(pathPrefix + "p1.png"));
        pics.add(new File(pathPrefix + "p2.png")); 
    
        // 附件
        List<File> attachments = new ArrayList();
        attachments.add(new File(pathPrefix + "a1.txt"));
        attachments.add(new File(pathPrefix + "a2.txt"));
        
        Mail mail = new Mail();
        mail.setSender(sender);
        mail.setRecipientList(recipientList);
        mail.setSubject("搜狐测试主题-完整邮件");
        mail.setHtml("<h1>1a汉字</h1><img src='p1.png'><img src='p2.png'>");
        mail.setPicList(pics);
        mail.setAttachmentList(attachments);
    
        return mail;
    }

常用邮件商

邮件商 SMTP服务器 SMTP端口
搜狐邮箱 smtp.sohu.com 25
QQ邮箱 smtp.qq.com 25

jmail's People

Contributors

ljn26 avatar zhoubin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.