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);
    }
    }
  • 相关阅读:
    JS_ECMA基本语法中的几种封装的小函数-1
    DOM_06之定时器、事件、cookie
    DOM_05之DOM、BOM常用对象
    OC数组中文排序
    uiwebview加载中文URL
    ios判断点击的坐标点
    获取字符串在另一个字符串中出现的次数
    NSFileHandle
    NSFileManager
    NSData
  • 原文地址:https://www.cnblogs.com/god-monk/p/11322283.html
Copyright © 2011-2022 走看看