日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring整合Quartz定时发送邮件

發布時間:2025/7/14 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring整合Quartz定时发送邮件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
功能描述:剛開始接觸Quartz,試著用Quartz整合spring實現每隔一分鐘發送一封郵件連續發送10次核心jar:郵件發送:commons-email-1.2.jar mail.jar(必須的)quartz:quartz-all-1.8.3.jar quartz-all-1.8.3/lib/下所有jarspring:spring-context-support.ajr(必須的)只貼出核心代碼:Email發送:使用apache commons-email跟mailpackage com.ssh.commonsemail;import java.util.ArrayList;import java.util.Date;import java.util.List;import javax.mail.internet.InternetAddress;import org.apache.commons.mail.SimpleEmail;/*** 功能描述:此代碼主要實現郵件發送功能* @author coder**/public class SendSimplEmail {public static void sendMail()throws Exception{List<InternetAddress> list=new ArrayList<InternetAddress>();list.add(new InternetAddress("313698683@qq.com"));list.add(new InternetAddress("184675420@qq.com"));SimpleEmail email=new SimpleEmail();email.setFrom("184675420@163.com");email.setCharset("utf-8");email.setSentDate(new Date());email.setSubject("測試Quartz");email.setHostName("smtp.163.com");email.setAuthentication("xxxx", "xxxx");email.setTo(list);email.setContent("<h1>Hello,把鳳姐許配給你,你看咋樣?</h1>", "text/html;charset=utf-8");email.send();}}定義調度工作任務:繼承自org.springframework.scheduling.quartz.QuartzJobBean次類在spring-context-support.jar中package com.ssh.quantz;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import org.springframework.scheduling.quartz.QuartzJobBean;import com.ssh.commonsemail.SendSimplEmail;/*** 發送email任務* @author coder**/public class SendEmailJob extends QuartzJobBean{@Overrideprotected void executeInternal(JobExecutionContext context)throws JobExecutionException {try {//調用郵件發送代碼 SendSimplEmail.sendMail();} catch (Exception e) {e.printStackTrace();}}}spring核心配置文件<!-- 定義調度工作任務 --><bean id="quantzjobBean" class="org.springframework.scheduling.quartz.JobDetailBean"><property name="jobClass"><!-- 實現了org.springframework.scheduling.quartz.QuartzJobBean的JobBean --><value>com.ssh.quantz.SendEmailJob</value></property><!-- 調用業務邏輯 --><!-- <property name="jobDataAsMap"><map><entry key="biz"><ref bean="users"/></entry></map></property>--></bean><!-- 觸發任務條件 --><bean id="simpletriggerbean" class="org.springframework.scheduling.quartz.SimpleTriggerBean"><property name="jobDetail" ref="quantzjobBean"></property><property name="cronExpression"><value>0 47 10 ? * *</value> //每天10點47觸發</property></bean><!-- 啟動調度 --><bean id="startQuartz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="simpletriggerbean"/></list></property></bean>

?

轉載于:https://www.cnblogs.com/yaowen/p/3777409.html

總結

以上是生活随笔為你收集整理的Spring整合Quartz定时发送邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。