zoukankan      html  css  js  c++  java
  • SpringBoot+JMail

    1.导入jar
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    <version>2.1.6.RELEASE</version>
    </dependency>
    2.SpringBoot配置
    spring.mail.host=smtp.qq.com
    spring.mail.username=发送邮箱
    spring.mail.password=cutkvuqshjgobbcj
    spring.mail.protocol=smtp
    spring.mail.default-encoding=UTF-8

    3.编码
    public class MailUtil {
        @Autowired
    JavaMailSenderImpl mailSender;

    public void sendEmail(HashMap map) throws Exception{
    //创建一个复杂的消息邮件
    MimeMessage mimeMessage = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
    helper.setSubject((String) map.get("subject"));//邮件主题
    helper.setText((String) map.get("text"),true);//使用html,邮件内容
    helper.setTo((String) map.get("to"));//收件地址
    helper.setFrom((String) map.get("from"));//发件人
    String filePath = (String) map.get("file");//附件路径
    if(!StringUtils.isEmpty(filePath)){
    FileSystemResource fileSystemResource = new FileSystemResource(filePath);
    helper.addAttachment((String) map.get("newName"), fileSystemResource);
    }
    mailSender.send(mimeMessage);
    }
    }
  • 相关阅读:
    HBase的compact分析
    HBase Rowkey的散列与预分区设计
    Zookeeper 快速理解
    oozie 入门
    Apache Storm内部原理分析
    Java ArrayList源码剖析
    Java HashSet和HashMap源码剖析
    初步掌握Yarn的架构及原理
    UML用例图总结
    UML类图几种关系的总结
  • 原文地址:https://www.cnblogs.com/god-monk/p/11322283.html
Copyright © 2011-2022 走看看