@Bean public IntegrationFlow newsFlow() { return IntegrationFlows.from(MessageChannels.queue("newsChannel", 10)) .<SyndEntry, String> transform( payload -> "《" + payload.getTitle() + "》 " + payload.getLink() + getProperty("line.separator")) .enrichHeaders( //1 Mail.headers() .subject("来自Spring的新闻") .to("wisely-man@126.com") .from("wisely-man@126.com")) .handle(Mail.outboundAdapter("smtp.126.com") //2 .port(25) .protocol("smtp") .credentials("wisely-man@126.com", "******") .javaMailProperties(p -> p.put("mail.debug", "false")), e -> e.id("smtpOut")) .get(); }
@Bean public IntegrationFlow sendMailFlow() { return IntegrationFlows.from("sendMailChannel") .enrichHeaders(Mail.headers() .subjectFunction(m -> "foo") .from("foo@bar") .toFunction(m -> new String[] { "bar@baz" })) .handle(Mail.outboundAdapter("localhost") .port(smtpServer.getPort()) .credentials("user", "pw") .protocol("smtp") .javaMailProperties(p -> p.put("mail.debug", "false")), e -> e.id("sendMailEndpoint")) .get(); }