相关步骤

  • 配置发送邮件相关信息
 # 邮件服务配置mail:host: smtp.qiye.aliyun.comport: 465username: 发送者对应的邮箱账号password: 发送者对应的邮箱密码to: 目标邮箱账号,多个账号之间用英文逗号隔开;例如xxx@dd.com,www@dd.com
  • 编写邮箱发送服务
import com.oaker.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.security.Security;
import java.util.Properties;
@Component
@EnableScheduling //开启定时服务
public class MailServiceImpl {private static final Logger logger = LoggerFactory.getLogger(MailServiceImpl.class);@Value("${spring.mail.host}")private String host;@Value("${spring.mail.port}")private String port;@Value("${spring.mail.username}")private String username;@Value("${spring.mail.password}")private String password;@Value("${spring.mail.to}")private String to;@Scheduled(cron = "0 0 9 * * ? ") //每天上午九点发送邮件cron表达式具体用法可参考:https://blog.csdn.net/study_665/article/details/123506946public void sendUseHourExcel() {//设置SSL连接、邮件环境try {Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";Properties props = System.getProperties();props.setProperty("mail.smtp.host", host);props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);props.setProperty("mail.smtp.socketFactory.fallback", "false");//设置端口props.setProperty("mail.smtp.port", port);//启用调试props.setProperty("mail.debug", "true");props.setProperty("mail.smtp.socketFactory.port", port);props.setProperty("mail.smtp.auth", "true");//建立邮件会话Session session = Session.getDefaultInstance(props, new Authenticator() {@Overrideprotected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication(username, password);}});//建立邮件对象MimeMessage message = new MimeMessage(session);//设置邮件的发件人、收件人、主题//发件人账号message.setFrom(new InternetAddress(username));//收件人账号if (StringUtils.isEmpty(to)) {return;}String[] targets = to.split(",");Address[] addresses = new Address[targets.length];for (int i = 0; i < targets.length; i++) {addresses[i] = new InternetAddress(targets[i]);}message.setRecipients(Message.RecipientType.TO, addresses);//邮件标题message.setSubject("邮件标题");//内容Multipart multipart = new MimeMultipart();BodyPart contentPart = new MimeBodyPart();//邮件内容contentPart.setContent("您好,这是发送的邮件!", "text/html;charset=utf-8");multipart.addBodyPart(contentPart);message.setContent(multipart);Transport.send(message);} catch (Exception e) {e.printStackTrace();logger.info("发送邮箱失败:" + e.getMessage());}}
}

结语

如果以上文章对您有一点点帮助,希望您不要吝啬的点个赞加个关注,您每一次小小的举动都是我坚持写作的不懈动力!ღ( ´・ᴗ・` )

Java使用钉钉定时发送邮件到企业邮箱相关推荐

  1. linux下使用mail定时发送邮件-阿里企业邮箱发送

    一 背景介绍 文章需求: 编写脚本从数仓里提取数据,并将数据表格通过阿里企业邮箱发送给指定人员,这里主要讲下,使用mail命令发送邮件时遇到的一些坑. 个人公众号:放纵的Coder 有疑问请联系我 二 ...

  2. 定时运行python脚本并发送邮件_python实现定时发送邮件到指定邮箱

    本文实例为大家分享了python实现定时发送邮件到指定邮箱的具体代码,供大家参考,具体内容如下 整个链路:传感器采集端采集数据,边缘端上传数据库,从数据库拿到数据. 产品端有个自动出报告的需求,并且希 ...

  3. 利用Java的JavaMail发送邮件:企业邮箱版和个人邮箱客端版

    本文链接: http://blog.csdn.net/qq_35257397/article/details/79004987 废话不说进入正题: 1. 第一步 项目基于maven 搭建.引入pom. ...

  4. phpmailer发送邮件(QQ企业邮箱和163邮箱)

    注意:使用个人qq邮箱发送邮箱会被腾讯拦截发送失败 第一:163邮箱配置 1.登录163邮箱:https://email.163.com/ 2.在邮箱的设置中开启SMTP服务(设置->POP3/ ...

  5. qq企业邮箱用php发送邮件,qq 企业邮箱 php群发邮件

    普通邮箱群发邮件一般限制都比较多,比如说可发数量少等,但qq企业邮箱的邮件群发效果就要好很多,尤其是在结合phpmailer之后,今天一米软件就来和大家说一说qq企业邮箱php群发邮件. functi ...

  6. Java发邮件配置-hutool+腾讯企业邮箱

    1.技术选型 1.1.hutool工具 1.2.javax.mail 1.3.腾讯企业邮箱 2.环境准备 2.1.pom <!--javax.mail--><dependency&g ...

  7. python SMTP 发送邮件 阿里企业邮箱、163邮箱 及535错误

    class SendEmail(object):def __init__(self, type, to_addr):self.to_addr = to_addrself.sys_date = time ...

  8. qq企业邮箱 java发送_spring配置javamail利用qq企业邮箱发送邮件。

    javax.net.ssl.SSLSocketFactory false true true 25000 //java调用 @Resource private JavaMailSender mailS ...

  9. java EE 5配置邮件发送 qq企业邮箱

    为什么80%的码农都做不了架构师?>>>    java EE 5配置QQ企业邮件发送 1.在项目的WebRoot/META-INF/新建context.xml 具体内容如下: &l ...

最新文章

  1. 2021年大数据Spark(十五):Spark Core的RDD常用算子
  2. webpack 使用别名(resolve.alias)解决scss @import相对路径导致的问题
  3. python判断sqlite连接状态_python3 自动识别usb连接状态,即对usb重连的判断方法
  4. java中的System.out.print()与System.out.println()的区别
  5. 理解Flex itemRenderer(5)--效率
  6. leetcode 之Single Number(13)
  7. python使用ctypes模块下的windll.LoadLibrary报OSError: [WinError 193] % 不是有效的 Win32 应用程序...
  8. 教你设置eclipse自动生成的author等注释
  9. golang http Specifically check for timeout error
  10. 科大讯飞交通超脑荣获 2019 年大数据应用最佳实践案例 TOP10
  11. python带界面的人脸识别_PyQt5+Caffe+Opencv搭建人脸识别登录界面
  12. c语言主程序调用子程序数组,perl子程序返回多个数组到主程序中多个数组
  13. 资管运营BAND原创|那些年,资管运营业务交互中的酸甜苦辣
  14. sap 流程图 退货销售订单_ERP系统:退货流程的解决方案
  15. 【Nightingale (夜莺)监控系统安装配置】
  16. 服务器安全证书未生效怎么办,win7打开网页提示“该服务器的安全证书尚未生效...
  17. 算法题-排列组合问题
  18. Web在线客服系统源码
  19. 经典星号查看器查看密码
  20. java定时开始和关闭_springboot自带定时器实现定时任务的开启关闭以及定时时间可以配置详解...

热门文章

  1. scrapy图片-爬取哈利波特壁纸
  2. threat hunting. capability
  3. 漫谈MySQL六-系统数据库sys库详解
  4. muduo源码分析之Buffer
  5. 通信原理与MATLAB(五):FM的调制解调
  6. 陈道明:体会无用之事的美妙
  7. ADAS/ADS 整车下线标定解决方案
  8. Bshare自定义分享按钮
  9. swift 3迁移到swift5 swift版本迁移指南
  10. MyBase7定期破解