我在配置JavaMailSender
来创建和发送电子邮件时遇到麻烦。我的Spring Batch作业执行sendEmailStep
,但是从不创建电子邮件消息
下面是我有个
InstanceTestBatchConfiguration.java
在此配置中,我设置了一个sendEmailStep
来调用Tasklet
@Configuration
@EnableBatchProcessing
public class InstanceTestBatchConfiguration {
// tag::jobstep[]
@Bean(name = "mccINSTANCETESTjob")
public Job mccOrz004job(JobBuilderFactory jobFactory, //
@Qualifier("instanceTestSetupStep") Step orz004SetupStep, //
@Qualifier("callM204Step") Step callM204Step, //
@Qualifier("sendEmailStep") Step sendEmailStep, //
@Autowired SingleInstanceListener listener) { //
return jobFactory.get("mccINSTANCETESTjob") //
.incrementer(new RunIdIncrementer()) //
.start(orz004SetupStep) //
.next(sendEmailStep) //
.next(callM204Step) //
.build();
}
@Bean(name = "instanceTestSetupStep")
public Step instanceTestSetupStep(StepBuilderFactory stepFactory, InstanceTestSetupTasklet task) {
return stepFactory.get("instanceTestSetupStep") //
.tasklet(task) //
.allowStartIfComplete(true).build();
}
// end::jobstep[]
}
SendEmailTasklet.java 在这里,我设置了要发送的电子邮件示例
@Component
public class SendEmailTasklet implements Tasklet {
final static Logger LOGGER = LoggerFactory.getLogger(SendEmailTasklet.class);
@Autowired
public JavaMailSender emailSender;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo("exampleemail@google.com");
message.setSubject("Hello world");
message.setText("This is a test email");
emailSender.send(message);
return RepeatStatus.FINISHED;
}
}
application.properties 我有以下字段中设置,但省略对于它们的问题
spring.mail.host=xxx
spring.mail.port=xxx
#spring.mail.username=xxxx@xxx.com
#spring.mail.password=xxxx
spring.mail.properties.mail.smtp.auth=false
答案 0 :(得分:0)
没关系,它正在工作。我已经设置了像MailHog这样的邮件服务来处理传入和传出的电子邮件,并且未配置为释放电子邮件