SpringbootMailApplication应用启动类实现了ApplicationRunner接口,应用启动成功就执行run方法,发送4种邮件。
@SpringBootApplication public class SpringbootMailApplication implements ApplicationRunner { @Autowired IMailService mailService; public static void main( String[] args ) { SpringApplication.run(SpringbootMailApplication.class, args); } //启动应用后直接发送邮件 @Override public void run(ApplicationArguments args) throws Exception { // TODO Auto-generated method stub mailService.sendSimpleEmail(null, null, null); mailService.sendHtmlMail(null, null, null); mailService.sendFileMail(null, null, null,null); mailService.sendPictureMail(null, null, null,null); } }应用启动成功,并成功发送了4封邮件