使用Spring Email

时间:2017-06-05 13:20:58

标签: java spring email

我试图用Spring Email发送电子邮件。

我的豆子:

@Bean
public JavaMailSender getJavaMailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(„???“);
    mailSender.setPort(587);

    mailSender.setUsername(„???“);
    mailSender.setPassword(„???“);

    Properties props = mailSender.getJavaMailProperties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.debug", "true");

    return mailSender;
}

发送功能:

public void sendSimpleMessage(String to, String subject, String text) {

    SimpleMailMessage message = new SimpleMailMessage(); 
    message.setTo(to); 
    message.setSubject(subject); 
    message.setText(text);
    emailSender.send(message);
}

我收到了积极的回复,但电子邮件未送达。

250 OK id=1dHroI-0002US-95
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 smtprelay07.ispgateway.de closing connection

任何人都可以告诉我有什么不对吗?谢谢。

1 个答案:

答案 0 :(得分:1)

message.setFrom(...)解决了这个问题!