最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring Boot Mail QQ企業(yè)郵箱無(wú)法連接解決方案

 更新時(shí)間:2020年09月21日 11:11:46   作者:手撕高達(dá)的村長(zhǎng)  
這篇文章主要介紹了Spring Boot Mail QQ企業(yè)郵箱無(wú)法連接解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這里記錄一下QQ企業(yè)郵箱發(fā)郵件問(wèn)題,因?yàn)橹坝龅竭^(guò)一種情況是本地測(cè)試沒(méi)問(wèn)題,結(jié)果線上出現(xiàn)問(wèn)題

Couldn't connect to host, port: smtp.qq.com, 25; timeout -1

要使用企業(yè)郵箱生成的授權(quán)密碼.

這里只要是因?yàn)镼Q郵箱默認(rèn)端口是465,需要修改為SSL配置

java代碼

package com.chenpeng.cpeducloud.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Service;
 
import com.chenpeng.cpeducloud.base.WebConstants;
import com.chenpeng.cpeducloud.service.MailService;
import com.chenpeng.cpeducloud.util.Constants;
import com.chenpeng.cpeducloud.util.DateUtils;
import com.chenpeng.cpeducloud.util.StringUtils;
 
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 
/**auth : szy
 *time : 2019-05-16
 **/
@Service
@Slf4j
public class MailServiceImpl implements MailService {
 
  @Autowired
  private JavaMailSender mailSender;
 
  @Value("${mail.formSender}")
  private String sender;// 發(fā)送者
 
  @Value("${mail.formMobile}")
  private String formMobile;// 聯(lián)系電話
   
  /**
   * 發(fā)送簡(jiǎn)單郵件(收件人,主題,內(nèi)容)
   */
  @Override
  public void sendSimpleMail(String to, String subject, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(sender);
    message.setTo(to);
    message.setSubject(subject);
    message.setText(content);
    try {
      mailSender.send(message);
      log.info("簡(jiǎn)單郵件發(fā)送成功!");
    } catch (Exception e) {
      log.info("發(fā)送簡(jiǎn)單郵件時(shí)發(fā)生異常!"+e);
    }
  }
 
 
  /**
   * 發(fā)送Html郵件(收件人,主題,內(nèi)容)
   */
  @Override
  public void sendHtmlMail(String to, String subject, String content) {
    MimeMessage message = mailSender.createMimeMessage();
    try {
      MimeMessageHelper helper = null;  //true表示需要?jiǎng)?chuàng)建一個(gè)multipart message
      try {
        helper = new MimeMessageHelper(message, true);
        message.setFrom(sender);
        helper.setTo(to);
        helper.setSubject(subject);
        helper.setText(content, true);
        mailSender.send(message);
        log.info("html郵件發(fā)送成功");
      } catch (javax.mail.MessagingException e) {
        e.printStackTrace();
      }
 
    } catch (MessagingException e) {
      log.info("發(fā)送html郵件時(shí)發(fā)生異常!"+e);
    }
  }
 
  /**
   * 發(fā)送帶附件的郵件
   * @param to
   * @param subject
   * @param content
   * @param filePath
   */
  @Override
  public void sendAttachmentsMail(String to, String subject, String content, String filePath){
    MimeMessage message = mailSender.createMimeMessage();
 
    try {
      MimeMessageHelper helper = null;
      try {
        helper = new MimeMessageHelper(message, true);
        message.setFrom(sender);
        helper.setTo(to);
        helper.setSubject(subject);
        helper.setText(content, true);
 
        FileSystemResource file = new FileSystemResource(new File(filePath));
        String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
        helper.addAttachment(fileName, file);
        //helper.addAttachment("test"+fileName, file);
 
        mailSender.send(message);
        log.info("帶附件的郵件已經(jīng)發(fā)送。");
      } catch (javax.mail.MessagingException e) {
        e.printStackTrace();
      }
 
    } catch (MessagingException e) {
      log.info("發(fā)送帶附件的郵件時(shí)發(fā)生異常!"+e);
    }
  }
 
 
  /**
   * 發(fā)送Html郵件(收件人,主題,內(nèi)容),
   * 帶多附件
   */
  @Override
  public void sendHtmlMailAndAttachments(String[] to,String[] cc, String subject, String content, List<String> files) {
    MimeMessage message = mailSender.createMimeMessage();
    try {
      MimeMessageHelper helper = null;  //true表示需要?jiǎng)?chuàng)建一個(gè)multipart message
      try {
        helper = new MimeMessageHelper(message, true);
        message.setFrom(sender);
        helper.setTo(to);
        helper.setCc(cc);
        helper.setSubject(subject);
        helper.setText(content, true);
 
        for (String filePath : files){
          FileSystemResource file = new FileSystemResource(new File(filePath));
          String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
          helper.addAttachment(fileName, file);
        }
        mailSender.send(message);
        log.info("html郵件發(fā)送成功");
      } catch (javax.mail.MessagingException e) {
        e.printStackTrace();
      }
 
    } catch (MessagingException e) {
      log.info("發(fā)送html郵件時(shí)發(fā)生異常!"+e);
    }
  }
   
}

郵箱配置

#郵箱配置
mail:
 host: smtp.exmail.qq.com
 username: 11111@qq.com
 password: 密鑰不是密碼
 default-encoding: utf-8
 port: 465
 properties:
  mail:
   smtp:
    auth: true
    ssl:
     enable: true
     socketFactory:
      class: com.sun.mail.util.MailSSLSocketFactory
      fallback: false
    starttls:
        enable: true
        required: true

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • springboot調(diào)用webservice-soap接口的實(shí)現(xiàn)

    springboot調(diào)用webservice-soap接口的實(shí)現(xiàn)

    接口協(xié)議目前廣泛使用的有http協(xié)議和RPC協(xié)議和webservice,本文主要介紹了springboot調(diào)用webservice-soap接口的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • Spring JDBCTemplate原理及使用實(shí)例

    Spring JDBCTemplate原理及使用實(shí)例

    這篇文章主要介紹了Spring JDBCTemplate原理及使用實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • java創(chuàng)建jar包并被項(xiàng)目引用步驟詳解

    java創(chuàng)建jar包并被項(xiàng)目引用步驟詳解

    這篇文章主要介紹了java創(chuàng)建jar包并被項(xiàng)目引用步驟詳解,jar包實(shí)現(xiàn)了特定功能的,java字節(jié)碼文件的壓縮包,更多相關(guān)內(nèi)容需要的朋友可以參考一下
    2022-07-07
  • Spring AOP的幾種實(shí)現(xiàn)方式總結(jié)

    Spring AOP的幾種實(shí)現(xiàn)方式總結(jié)

    本篇文章主要介紹了Spring AOP的幾種實(shí)現(xiàn)方式總結(jié),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • java實(shí)戰(zhàn)之桌球小游戲

    java實(shí)戰(zhàn)之桌球小游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)戰(zhàn)之桌球小游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Java實(shí)現(xiàn)讀取文件夾下(包括子目錄)所有文件的文件名

    Java實(shí)現(xiàn)讀取文件夾下(包括子目錄)所有文件的文件名

    這篇文章主要介紹了Java實(shí)現(xiàn)讀取文件夾下(包括子目錄)所有文件的文件名,本文把代碼組織成了一個(gè)模塊,可以很方便的使用,需要的朋友可以參考下
    2015-06-06
  • Java中DecimalFormat用法及符號(hào)含義

    Java中DecimalFormat用法及符號(hào)含義

    DecimalFormat是NumberFormat的一個(gè)具體子類,用于格式化十進(jìn)制數(shù)字。這篇文章介紹了DecimalFormat的用法及符號(hào)含義,需要的朋友可以收藏下,方便下次瀏覽觀看
    2021-12-12
  • 詳解Spring Boot中如何自定義SpringMVC配置

    詳解Spring Boot中如何自定義SpringMVC配置

    這篇文章主要給大家介紹了關(guān)于Spring Boot中如何自定義SpringMVC配置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09
  • 教你java面試時(shí)如何聊單例模式

    教你java面試時(shí)如何聊單例模式

    這篇文章主要給大家介紹了關(guān)于Java單例模式推薦的幾種模式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-06-06
  • maven項(xiàng)目在實(shí)踐中的構(gòu)建管理之路的方法

    maven項(xiàng)目在實(shí)踐中的構(gòu)建管理之路的方法

    這篇文章主要介紹了maven項(xiàng)目在實(shí)踐中的構(gòu)建管理之路的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-05-05

最新評(píng)論

克什克腾旗| 杭锦后旗| 墨玉县| 专栏| 沾益县| 汤阴县| 宁河县| 十堰市| 锡林郭勒盟| 平江县| 和田县| 漳浦县| 都安| 西城区| 阳春市| 盖州市| 密山市| 柘荣县| 托里县| 鄂托克前旗| 长宁区| 巧家县| 林口县| 永济市| 贡嘎县| 绥棱县| 黄梅县| 滨海县| 鲁山县| 定安县| 密山市| 巴彦淖尔市| 浮梁县| 政和县| 黔东| 蛟河市| 莎车县| 舒城县| 沂水县| 柳州市| 灵武市|