色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Spring Boot Mail QQ企業郵箱無法連接解決方案

瀏覽:107日期:2022-06-25 13:00:34

這里記錄一下QQ企業郵箱發郵件問題,因為之前遇到過一種情況是本地測試沒問題,結果線上出現問題

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

Spring Boot Mail QQ企業郵箱無法連接解決方案

要使用企業郵箱生成的授權密碼.

這里只要是因為QQ郵箱默認端口是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@Slf4jpublic class MailServiceImpl implements MailService { @Autowired private JavaMailSender mailSender; @Value('${mail.formSender}') private String sender;// 發送者 @Value('${mail.formMobile}') private String formMobile;// 聯系電話 /** * 發送簡單郵件(收件人,主題,內容) */ @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('簡單郵件發送成功!'); } catch (Exception e) { log.info('發送簡單郵件時發生異常!'+e); } } /** * 發送Html郵件(收件人,主題,內容) */ @Override public void sendHtmlMail(String to, String subject, String content) { MimeMessage message = mailSender.createMimeMessage(); try { MimeMessageHelper helper = null; //true表示需要創建一個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郵件發送成功'); } catch (javax.mail.MessagingException e) {e.printStackTrace(); } } catch (MessagingException e) { log.info('發送html郵件時發生異常!'+e); } } /** * 發送帶附件的郵件 * @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('帶附件的郵件已經發送。'); } catch (javax.mail.MessagingException e) {e.printStackTrace(); } } catch (MessagingException e) { log.info('發送帶附件的郵件時發生異常!'+e); } } /** * 發送Html郵件(收件人,主題,內容), * 帶多附件 */ @Override public void sendHtmlMailAndAttachments(String[] to,String[] cc, String subject, String content, List<String> files) { MimeMessage message = mailSender.createMimeMessage(); try { MimeMessageHelper helper = null; //true表示需要創建一個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郵件發送成功'); } catch (javax.mail.MessagingException e) {e.printStackTrace(); } } catch (MessagingException e) { log.info('發送html郵件時發生異常!'+e); } } }

郵箱配置

#郵箱配置mail: host: smtp.exmail.qq.com username: [email protected] 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: truerequired: true

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: qq
相關文章:
主站蜘蛛池模板: 性做爰片免费视频毛片中文i | 欧美久久久久久久久 | 欧美精品一区二区三区免费播放 | 久草综合视频在线 | 国产成人a一区二区 | 国产理论视频在线观看 | 亚洲精品一区二区在线观看 | 国产一级视频在线 | 日本aaaa级毛片在线看 | 日本人视频网站一 | 亚洲国产天堂久久综合网站 | 国产精品19p | freesex寂寞老妇hd | 99精品视频99 | 国产精品手机在线播放 | 日韩色综合 | 香蕉成人在线 | 9久9久女女热精品视频免费观看 | 国产女女视屏免费 | 三级视频网站 | 欧美成人一级片 | 欧美日韩一区二区三区视视频 | 国产精品一区二区免费 | 亚洲国产午夜精品理论片的软件 | 91久久国产综合精品女同国语 | 亚洲天堂在线视频播放 | 亚洲一级高清在线中文字幕 | 国产成人3p视频免费观看 | 国产成人免费手机在线观看视频 | 亚洲成年人网址 | 精品日本一区二区三区在线观看 | 亚洲欧洲无码一区二区三区 | 毛片免费高清免费 | 日本高清在线精品一区二区三区 | 夜色伊人 | 成人国产精品久久久免费 | 国产人做人爱免费视频 | 久久成人在线 | 亚洲a成人| 免费在线观看黄色毛片 | 亚洲视频一区二区在线观看 |