如何配置spring lemon通过Sendgrid发送电子邮件?

时间:2016-06-14 10:46:07

标签: spring-lemon

我通过sendgrid的SMTP api成功发送了电子邮件,但没有更改我的spring-lemon代码。我只是通过在cloudfoundry上配置环境变量来做到这一点。

我现在想使用sendgrid java library

然后我创建了以下类

    SendGrid sendgrid = new SendGrid('api_key');

SendGrid.Email email = new SendGrid.Email();
email.addTo("example@example.com");
email.setFrom("other@example.com");
email.setSubject("Hello World");
email.setText("My first email with SendGrid Java!");

try {
  SendGrid.Response response = sendgrid.send(email);
  System.out.println(response.getMessage());
}
catch (SendGridException e) {
  System.err.println(e);
}

如何让spring-lemon使用此类而不是SmtpMailSender?

1 个答案:

答案 0 :(得分:0)

拥有NewFile的自定义实现,并将其配置为bean应该会抑制Spring Lemon的MailSender配置,因为Spring Lemon的SmtpMailSender类已注释与MailConfiguration。 (请参阅蓝图书的第79页 - 允许开发人员提供他们的实现

@ConditionalOnMissingBean(MailSender.class)是臭名昭着的,但我在这种情况下测试了它。

相关问题