0
請幫我寫一個電子郵件發送的集成測試,inreal發送電子郵件。電子郵件發送集成測試
public interface MailSenderService {
void sendEmail(String to, String from, String subject, String body); }
郵件發件人類
@Service
public class MailSenderServiceImpl implements MailSenderService {
private static final Logger logger = LoggerFactory.getLogger(MailSenderServiceImpl.class);
@Autowired
private JavaMailSender javaMailSender;
@Autowired
Configuration freemarkerConfiguration;
private SimpleMailMessage composeMail(String to, String from, String subject, String body) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(body);
return message;
}
@Override
public void sendEmail(String to, String from, String subject, String body) {
sendMessage(composeMail(to, from, subject, body));
}
@Async
private void sendMessage(SimpleMailMessage message) {
Assert.notNull(javaMailSender, "Email Sender must not be null");
javaMailSender.send(message);
}}
最後這裏是一個集成測試,其不通過:
public class MailSenderServiceIT extends BaseServiceIntegrationTest {
@Autowired
private MailSenderService mailSenderService;
@Test
public void sendEmail() {
mailSenderService.sendEmail("[email protected]", "[email protected]", "Test Subject",
"Test Body");
flushAndClear();
}
我使用這些屬性的郵件發送: smtp.host = SMTP .gmail.com smtp.port = 587 [email protected] smtp.password = aaa12345678 $ – Mary
運行測試我收到MailAuthenticationException – Mary