{"id":30324,"date":"2014-09-20T15:00:31","date_gmt":"2014-09-20T12:00:31","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=30324"},"modified":"2014-09-20T09:13:46","modified_gmt":"2014-09-20T06:13:46","slug":"testing-mail-code-in-spring-boot-application","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html","title":{"rendered":"Testing mail code in Spring Boot application"},"content":{"rendered":"<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/09\/logo-spring-io.png\"><img decoding=\"async\" class=\"alignright size-medium wp-image-30456\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/09\/logo-spring-io-300x94.png\" alt=\"logo-spring-io\" width=\"300\" height=\"94\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/09\/logo-spring-io-300x94.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/09\/logo-spring-io.png 352w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not differ much from configuring it in Spring Bootless application. But how to test that mail configuration and submission is working fine? Let\u2019s have a look.<\/p>\n<p>I assume that we have a simple Spring Boot application bootstrapped. If not, the easiest way to do it is by using the <a href=\"http:\/\/start.spring.io\/\">Spring Initializr<\/a>.<\/p>\n<h2>Adding javax.mail dependency<\/h2>\n<p>We start by adding <code>javax.mail<\/code> dependency to <code>build.gradle<\/code>: <code>compile 'javax.mail:mail:1.4.1'<\/code>. We will also need <code>Spring Context Support<\/code> (if not present) that contains <code>JavaMailSender<\/code> support class. The dependency is: <code>compile(\"org.springframework:spring-context-support\")<\/code><\/p>\n<h2>Java-based Configuration<\/h2>\n<p>Spring Boot favors Java-based configuration. In order to add mail configuration, we add <code>MailConfiguration<\/code> class annotated with <code>@Configuration<\/code> annotation. The properties are stored in <code>mail.properties<\/code> (it is not required, though). Property values can be injected directly into beans using the <code>@Value<\/code> annotation:<\/p>\n<pre class=\" brush:java\">@Configuration\r\n@PropertySource(\"classpath:mail.properties\")\r\npublic class MailConfiguration {\r\n\r\n    @Value(\"${mail.protocol}\")\r\n    private String protocol;\r\n    @Value(\"${mail.host}\")\r\n    private String host;\r\n    @Value(\"${mail.port}\")\r\n    private int port;\r\n    @Value(\"${mail.smtp.auth}\")\r\n    private boolean auth;\r\n    @Value(\"${mail.smtp.starttls.enable}\")\r\n    private boolean starttls;\r\n    @Value(\"${mail.from}\")\r\n    private String from;\r\n    @Value(\"${mail.username}\")\r\n    private String username;\r\n    @Value(\"${mail.password}\")\r\n    private String password;\r\n\r\n    @Bean\r\n    public JavaMailSender javaMailSender() {\r\n        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();\r\n        Properties mailProperties = new Properties();\r\n        mailProperties.put(\"mail.smtp.auth\", auth);\r\n        mailProperties.put(\"mail.smtp.starttls.enable\", starttls);\r\n        mailSender.setJavaMailProperties(mailProperties);\r\n        mailSender.setHost(host);\r\n        mailSender.setPort(port);\r\n        mailSender.setProtocol(protocol);\r\n        mailSender.setUsername(username);\r\n        mailSender.setPassword(password);\r\n        return mailSender;\r\n    }\r\n}<\/pre>\n<p>The <code>@PropertySource<\/code> annotation makes <code>mail.properties<\/code> available for injection with <code>@Value<\/code>. annotation. If not done, you may expect an exception: <code>java.lang.IllegalArgumentException: Could not resolve placeholder '&lt;name&gt;' in string value \"${&lt;name&gt;}\"<\/code>.<\/p>\n<p>And the <code>mail.properties<\/code>:<\/p>\n<pre class=\" brush:java\">mail.protocol=smtp\r\nmail.host=localhost\r\nmail.port=25\r\nmail.smtp.auth=false\r\nmail.smtp.starttls.enable=false\r\nmail.from=me@localhost\r\nmail.username=\r\nmail.password=<\/pre>\n<h2>Mail endpoint<\/h2>\n<p>In order to be able to send an email in our application, we can create a REST endpoint. We can use Spring\u2019s <code>SimpleMailMessage<\/code> in order to quickly implement this endpoint. Let\u2019s have a look:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">@RestController\r\nclass MailSubmissionController {\r\n\r\n    private final JavaMailSender javaMailSender;\r\n\r\n    @Autowired\r\n    MailSubmissionController(JavaMailSender javaMailSender) {\r\n        this.javaMailSender = javaMailSender;\r\n    }\r\n\r\n    @RequestMapping(\"\/mail\")\r\n    @ResponseStatus(HttpStatus.CREATED)\r\n    SimpleMailMessage send() {        \r\n        SimpleMailMessage mailMessage = new SimpleMailMessage();\r\n        mailMessage.setTo(\"someone@localhost\");\r\n        mailMessage.setReplyTo(\"someone@localhost\");\r\n        mailMessage.setFrom(\"someone@localhost\");\r\n        mailMessage.setSubject(\"Lorem ipsum\");\r\n        mailMessage.setText(\"Lorem ipsum dolor sit amet [...]\");\r\n        javaMailSender.send(mailMessage);\r\n        return mailMessage;\r\n    }\r\n}<\/pre>\n<h2>Running the application<\/h2>\n<p>We are now ready to run the application. If you use CLI, type: <code>gradle bootRun<\/code>, open the browser and navigate to <code>localhost:8080\/mail<\/code>. What you should see is actually an error, saying that mail server connection failed. As expected.<\/p>\n<h2>Fake SMTP Server<\/h2>\n<p><a href=\"http:\/\/nilhcem.github.io\/FakeSMTP\/index.html\">FakeSMTP<\/a> is a free Fake SMTP Server with GUI, written in Java, for testing emails in applications. We will use it to verify if the submission works. Please download the application and simply run it by invoking: <code>java -jar fakeSMTP-&lt;version&gt;.jar<\/code>. After launching Fake SMTP Server, start the server.<\/p>\n<p>Now you can invoke REST endpoint again and see the result in Fake SMTP!<\/p>\n<p>But by testing I did not mean manual testing! The application is still useful, but we want to <strong>automatically<\/strong> test mail code.<\/p>\n<h2>Unit testing mail code<\/h2>\n<p>To be able to automatically test the mail submission, we will use <a href=\"https:\/\/code.google.com\/p\/subethasmtp\/wiki\/Wiser\">Wiser<\/a> &#8211; a framework \/ utility for unit testing mail based on <a href=\"https:\/\/code.google.com\/p\/subethasmtp\/\">SubEtha SMTP<\/a>. <em>SubEthaSMTP\u2019s simple, low-level API is suitable for writing almost any kind of mail-receiving application.<\/em><\/p>\n<p>Using Wiser is very simple. Firstly, we need to add a test dependency to <code>build.gradle<\/code>: <code>testCompile(\"org.subethamail:subethasmtp:3.1.7\")<\/code>. Secondly, we create an integration test with, JUnit, Spring and and Wiser:<\/p>\n<pre class=\" brush:java\">@RunWith(SpringJUnit4ClassRunner.class)\r\n@SpringApplicationConfiguration(classes = Application.class)\r\n@WebAppConfiguration\r\npublic class MailSubmissionControllerTest {\r\n\r\n    private Wiser wiser;\r\n\r\n    @Autowired\r\n    private WebApplicationContext wac;\r\n    private MockMvc mockMvc;\r\n\r\n\r\n    @Before\r\n    public void setUp() throws Exception {\r\n        wiser = new Wiser();\r\n        wiser.start();\r\n        mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();\r\n    }\r\n\r\n    @After\r\n    public void tearDown() throws Exception {\r\n        wiser.stop();\r\n    }\r\n\r\n    @Test\r\n    public void send() throws Exception {\r\n        \/\/ act\r\n        mockMvc.perform(get(\"\/mail\"))\r\n                .andExpect(status().isCreated());\r\n        \/\/ assert\r\n        assertReceivedMessage(wiser)\r\n                .from(\"someone@localhosts\")\r\n                .to(\"someone@localhost\")\r\n                .withSubject(\"Lorem ipsum\")\r\n                .withContent(\"Lorem ipsum dolor sit amet [...]\");\r\n    }\r\n}<\/pre>\n<p>The SMTP server is initialized, started in <code>@Before<\/code> method and stopped in <code>@Teardown<\/code> method. After sending a message, the assertion is made. The assertion needs to be created, as the framework does not provide any. As you will notice, we need to operate on Wiser object, that provides a list of received messages:<\/p>\n<pre class=\" brush:java;wrap-lines:false\">public class WiserAssertions {\r\n\r\n    private final List&lt;WiserMessage&gt; messages;\r\n\r\n    public static WiserAssertions assertReceivedMessage(Wiser wiser) {\r\n        return new WiserAssertions(wiser.getMessages());\r\n    }\r\n\r\n    private WiserAssertions(List&lt;WiserMessage&gt; messages) {\r\n        this.messages = messages;\r\n    }\r\n\r\n    public WiserAssertions from(String from) {\r\n        findFirstOrElseThrow(m -&gt; m.getEnvelopeSender().equals(from),\r\n                assertionError(\"No message from [{0}] found!\", from));\r\n        return this;\r\n    }\r\n\r\n    public WiserAssertions to(String to) {\r\n        findFirstOrElseThrow(m -&gt; m.getEnvelopeReceiver().equals(to),\r\n                assertionError(\"No message to [{0}] found!\", to));\r\n        return this;\r\n    }\r\n\r\n    public WiserAssertions withSubject(String subject) {\r\n        Predicate&lt;WiserMessage&gt; predicate = m -&gt; subject.equals(unchecked(getMimeMessage(m)::getSubject));\r\n        findFirstOrElseThrow(predicate,\r\n                assertionError(\"No message with subject [{0}] found!\", subject));\r\n        return this;\r\n    }\r\n\r\n    public WiserAssertions withContent(String content) {\r\n        findFirstOrElseThrow(m -&gt; {\r\n            ThrowingSupplier&lt;String&gt; contentAsString = \r\n                () -&gt; ((String) getMimeMessage(m).getContent()).trim();\r\n            return content.equals(unchecked(contentAsString));\r\n        }, assertionError(\"No message with content [{0}] found!\", content));\r\n        return this;\r\n    }\r\n\r\n    private void findFirstOrElseThrow(Predicate&lt;WiserMessage&gt; predicate, Supplier&lt;AssertionError&gt; exceptionSupplier) {\r\n        messages.stream().filter(predicate)\r\n                .findFirst().orElseThrow(exceptionSupplier);\r\n    }\r\n\r\n    private MimeMessage getMimeMessage(WiserMessage wiserMessage) {\r\n        return unchecked(wiserMessage::getMimeMessage);\r\n    }\r\n\r\n    private static Supplier&lt;AssertionError&gt; assertionError(String errorMessage, String... args) {\r\n        return () -&gt; new AssertionError(MessageFormat.format(errorMessage, args));\r\n    }\r\n\r\n    public static &lt;T&gt; T unchecked(ThrowingSupplier&lt;T&gt; supplier) {\r\n        try {\r\n            return supplier.get();\r\n        } catch (Throwable e) {\r\n            throw new RuntimeException(e);\r\n        }\r\n    }\r\n\r\n    interface ThrowingSupplier&lt;T&gt; {\r\n        T get() throws Throwable;\r\n    }\r\n}<\/pre>\n<h2>Summary<\/h2>\n<p>With just couple of lines of code we were able to automatically test mail code. The example presented in this article is not sophisticated but it shows how easy it is to get started with SubEtha SMTP and Wiser.<\/p>\n<p>How do you test your mail code?<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/blog.codeleak.pl\/2014\/09\/testing-mail-code-in-spring-boot.html\">Testing mail code in Spring Boot application<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Rafal Borowiec at the <a href=\"http:\/\/blog.codeleak.pl\/\">Codeleak.pl<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not differ much from configuring it in Spring Bootless application. But how to test that mail configuration and submission is working fine? Let\u2019s have a look. I assume that we have &hellip;<\/p>\n","protected":false},"author":516,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,854],"class_list":["post-30324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Testing mail code in Spring Boot application<\/title>\n<meta name=\"description\" content=\"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testing mail code in Spring Boot application\" \/>\n<meta property=\"og:description\" content=\"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-09-20T12:00:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rafal Borowiec\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/kolorobot\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rafal Borowiec\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html\"},\"author\":{\"name\":\"Rafal Borowiec\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b1a0b2657d5dd2459806446ac66d2d52\"},\"headline\":\"Testing mail code in Spring Boot application\",\"datePublished\":\"2014-09-20T12:00:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html\"},\"wordCount\":511,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html\",\"name\":\"Testing mail code in Spring Boot application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2014-09-20T12:00:31+00:00\",\"description\":\"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/09\\\/testing-mail-code-in-spring-boot-application.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Testing mail code in Spring Boot application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b1a0b2657d5dd2459806446ac66d2d52\",\"name\":\"Rafal Borowiec\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"caption\":\"Rafal Borowiec\"},\"description\":\"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.\",\"sameAs\":[\"http:\\\/\\\/blog.codeleak.pl\\\/\",\"http:\\\/\\\/pl.linkedin.com\\\/in\\\/borowiec\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/kolorobot\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/rafal-borowiec\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testing mail code in Spring Boot application","description":"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html","og_locale":"en_US","og_type":"article","og_title":"Testing mail code in Spring Boot application","og_description":"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not","og_url":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-09-20T12:00:31+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Rafal Borowiec","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/kolorobot","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rafal Borowiec","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html"},"author":{"name":"Rafal Borowiec","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b1a0b2657d5dd2459806446ac66d2d52"},"headline":"Testing mail code in Spring Boot application","datePublished":"2014-09-20T12:00:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html"},"wordCount":511,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html","url":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html","name":"Testing mail code in Spring Boot application","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2014-09-20T12:00:31+00:00","description":"Whilst building a Spring Boot application you may encounter a need of adding a mail configuration. Actually, configuring the mail in Spring Boot does not","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/09\/testing-mail-code-in-spring-boot-application.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Testing mail code in Spring Boot application"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b1a0b2657d5dd2459806446ac66d2d52","name":"Rafal Borowiec","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","caption":"Rafal Borowiec"},"description":"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.","sameAs":["http:\/\/blog.codeleak.pl\/","http:\/\/pl.linkedin.com\/in\/borowiec\/","https:\/\/x.com\/https:\/\/twitter.com\/kolorobot"],"url":"https:\/\/www.javacodegeeks.com\/author\/rafal-borowiec"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/30324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/516"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=30324"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/30324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=30324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=30324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=30324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}