From b4e08ae135a49b29f3dad6b00e41197e5d833504 Mon Sep 17 00:00:00 2001 From: Ben Klein Date: Tue, 25 Aug 2015 19:08:35 -0700 Subject: [PATCH] add SMTP examples to Spring Service Connector doc --- ...spring-cloud-spring-service-connector.adoc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-spring-service-connector.adoc b/docs/src/main/asciidoc/spring-cloud-spring-service-connector.adoc index 880489b..142425f 100644 --- a/docs/src/main/asciidoc/spring-cloud-spring-service-connector.adoc +++ b/docs/src/main/asciidoc/spring-cloud-spring-service-connector.adoc @@ -329,6 +329,30 @@ public RedisConnectionFactory redisFactory() { } ---- +==== SMTP + +To connect to a unique SMTP service, you can create a service bean using `service()`, providing the service type http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/MailSender.html[`MailSender`]. The following example connects to the only SMTP service bound to the application. + +[source,java] +---- +//Connect to the only available SMTP service +@Bean +public MailSender mailSender() { + return connectionFactory().service(MailSender.class); +} +---- + +To connect to a specific SMTP service, you can use an overloaded variant of `service()`, providing the service type http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/MailSender.html[`MailSender`]. The following example connects specifically to the `mail-service` SMTP service. + +[source,java] +---- +//Connect to the 'mail-service' SMTP service +@Bean +public MailSender mailSender() { + return connectionFactory().service("mail-service", MailSender.class); +} +---- + === Connecting to Generic Services The Java configuration supports access to generic services (services which don't have a directly mapped method; this is typical for a newly-introduced service or when connecting to a private service in a private PaaS) through the `service()` method. It follows the same pattern as `dataSource()` etc., except that it allows you to supply the connector type as an additional parameter. The following example connects to a hypothetical service of type `Search`, called `search-service`.