{"id":464,"date":"2009-08-23T19:45:57","date_gmt":"2009-08-23T22:45:57","guid":{"rendered":"https:\/\/devkico.itexto.com.br\/?p=464"},"modified":"2009-08-23T19:45:57","modified_gmt":"2009-08-23T22:45:57","slug":"sending-e-mails-with-grails-the-simple-way","status":"publish","type":"post","link":"https:\/\/devkico.itexto.com.br\/?p=464","title":{"rendered":"Sending e-mails with Grails: the simple way"},"content":{"rendered":"<p><a href=\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-462\" style=\"margin: 20px;\" title=\"email\" src=\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png\" alt=\"\" width=\"210\" height=\"300\" srcset=\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png 210w, https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email.png 224w\" sizes=\"(max-width: 210px) 100vw, 210px\" \/><\/a> Sending e-mails with Grails can be quite complicated (yeap, I know about the <a href=\"http:\/\/grails.org\/Mail+Plugin\" target=\"_blank\">Mail Plugin<\/a>, but I also know many people who had some problems with it AND it&#8217;s a Grails only alternative).<\/p>\n<p>If you don\u00b4t want to use a plugin, you can always count with the <a href=\"http:\/\/java.sun.com\/products\/javamail\/\" target=\"_blank\">Java Mail API<\/a>, or even the <a href=\"http:\/\/static.springsource.org\/spring\/docs\/1.2.x\/reference\/mail.html\">Spring Framework<\/a> support for it, right? Yeah, right: but at least for me, it seems like a to complex solution for a simple need. So, I started my quest for a simple way to do it. The solution I found was right in front of me all the time (so usual&#8230;): Commons E-mail, which is part of the Apache Commons project!<\/p>\n<p>To show how you can use it, here is a small snippet:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\r\nimport org.apache.commons.mail.SimpleEmail\r\nclass MailService {\r\n\r\nboolean transactional = false\r\n\/\/ I added the configuration on the same class just for the sake of simplicity (you should NEVER do this on a real case)\r\nString host= &quot;your.mail.ver&quot;\r\nString username = &quot;your.login&quot;\r\nString password = &quot;your.password&quot;\r\nString from = &quot;me@me.com&quot;\r\nInteger port = 465\r\n\r\ndef send(String subject, String msg, String to) {\r\n\r\n\/\/SimpleEmail is the class which will do all the hard work for you\r\nSimpleEmail email = new SimpleEmail()\r\nemail.setHostName(host)\r\nemail.addTo(to)\r\nemail.setFrom(from)\r\nemail.setSubject(subject)\r\nemail.setMsg(msg)\r\n\r\n\/\/If you need authentication, this is the method\r\nemail.setAuthentication(username,password)\r\n\r\n\/\/ If you need to specify your smtp port, this is how to\r\nemail.setSmtpPort(port)\r\n\r\n\/\/ So all you need to do is call the method send() and your e-mail will be delivered (at least in theory)\r\nemail.send()\r\n}\r\n}\r\n\r\n<\/pre>\n<p>Just like I wanted: simple!<\/p>\n<p><strong>Dependencies<\/strong><\/p>\n<p>All you need is JAF, which may be downloaded on the following link:   <a href=\"http:\/\/java.sun.com\/javase\/technologies\/desktop\/javabeans\/jaf\/index.jsp\" target=\"_blank\">http:\/\/java.sun.com\/javase\/technologies\/desktop\/javabeans\/jaf\/index.jsp<\/a><\/p>\n<p><strong>Where to download Commons E-mail:<\/strong> <a href=\"http:\/\/commons.apache.org\/email\/\" target=\"_blank\">http:\/\/commons.apache.org\/email\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sending e-mails with Grails can be quite complicated (yeap, I know about the Mail Plugin, but I also know many people who had some problems with it AND it&#8217;s a Grails only alternative). If you don\u00b4t want to use a plugin, you can always count with the Java Mail API, or even the Spring Framework [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-grails","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Sending e-mails with Grails: the simple way - \/dev\/Kico<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/devkico.itexto.com.br\/?p=464\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sending e-mails with Grails: the simple way - \/dev\/Kico\" \/>\n<meta property=\"og:description\" content=\"Sending e-mails with Grails can be quite complicated (yeap, I know about the Mail Plugin, but I also know many people who had some problems with it AND it&#8217;s a Grails only alternative). If you don\u00b4t want to use a plugin, you can always count with the Java Mail API, or even the Spring Framework [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devkico.itexto.com.br\/?p=464\" \/>\n<meta property=\"og:site_name\" content=\"\/dev\/Kico\" \/>\n<meta property=\"article:published_time\" content=\"2009-08-23T22:45:57+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.itexto.net\/devkico\/wp-content\/uploads\/2009\/08\/email-210x300.png\" \/>\n<meta name=\"author\" content=\"Kico (Henrique Lobo Weissmann)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@loboweissmann\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kico (Henrique Lobo Weissmann)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464\",\"url\":\"https:\/\/devkico.itexto.com.br\/?p=464\",\"name\":\"Sending e-mails with Grails: the simple way - \/dev\/Kico\",\"isPartOf\":{\"@id\":\"https:\/\/devkico.itexto.com.br\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage\"},\"image\":{\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage\"},\"thumbnailUrl\":\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png\",\"datePublished\":\"2009-08-23T22:45:57+00:00\",\"dateModified\":\"2009-08-23T22:45:57+00:00\",\"author\":{\"@id\":\"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/502ab8892631bb005d6da2269fe5a3a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devkico.itexto.com.br\/?p=464\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage\",\"url\":\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png\",\"contentUrl\":\"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devkico.itexto.com.br\/?p=464#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devkico.itexto.com.br\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sending e-mails with Grails: the simple way\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/devkico.itexto.com.br\/#website\",\"url\":\"https:\/\/devkico.itexto.com.br\/\",\"name\":\"\/dev\/Kico\",\"description\":\"Desenvolvendo software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/devkico.itexto.com.br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/502ab8892631bb005d6da2269fe5a3a7\",\"name\":\"Kico (Henrique Lobo Weissmann)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd6973d86a689bc63122b2e603f25be3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd6973d86a689bc63122b2e603f25be3?s=96&d=mm&r=g\",\"caption\":\"Kico (Henrique Lobo Weissmann)\"},\"sameAs\":[\"https:\/\/x.com\/loboweissmann\"],\"url\":\"https:\/\/devkico.itexto.com.br\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sending e-mails with Grails: the simple way - \/dev\/Kico","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:\/\/devkico.itexto.com.br\/?p=464","og_locale":"pt_BR","og_type":"article","og_title":"Sending e-mails with Grails: the simple way - \/dev\/Kico","og_description":"Sending e-mails with Grails can be quite complicated (yeap, I know about the Mail Plugin, but I also know many people who had some problems with it AND it&#8217;s a Grails only alternative). If you don\u00b4t want to use a plugin, you can always count with the Java Mail API, or even the Spring Framework [&hellip;]","og_url":"https:\/\/devkico.itexto.com.br\/?p=464","og_site_name":"\/dev\/Kico","article_published_time":"2009-08-23T22:45:57+00:00","og_image":[{"url":"http:\/\/www.itexto.net\/devkico\/wp-content\/uploads\/2009\/08\/email-210x300.png"}],"author":"Kico (Henrique Lobo Weissmann)","twitter_card":"summary_large_image","twitter_creator":"@loboweissmann","twitter_misc":{"Escrito por":"Kico (Henrique Lobo Weissmann)","Est. tempo de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devkico.itexto.com.br\/?p=464","url":"https:\/\/devkico.itexto.com.br\/?p=464","name":"Sending e-mails with Grails: the simple way - \/dev\/Kico","isPartOf":{"@id":"https:\/\/devkico.itexto.com.br\/#website"},"primaryImageOfPage":{"@id":"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage"},"image":{"@id":"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage"},"thumbnailUrl":"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png","datePublished":"2009-08-23T22:45:57+00:00","dateModified":"2009-08-23T22:45:57+00:00","author":{"@id":"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/502ab8892631bb005d6da2269fe5a3a7"},"breadcrumb":{"@id":"https:\/\/devkico.itexto.com.br\/?p=464#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devkico.itexto.com.br\/?p=464"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/devkico.itexto.com.br\/?p=464#primaryimage","url":"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png","contentUrl":"https:\/\/devkico.itexto.com.br\/wp-content\/uploads\/2009\/08\/email-210x300.png"},{"@type":"BreadcrumbList","@id":"https:\/\/devkico.itexto.com.br\/?p=464#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devkico.itexto.com.br\/"},{"@type":"ListItem","position":2,"name":"Sending e-mails with Grails: the simple way"}]},{"@type":"WebSite","@id":"https:\/\/devkico.itexto.com.br\/#website","url":"https:\/\/devkico.itexto.com.br\/","name":"\/dev\/Kico","description":"Desenvolvendo software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/devkico.itexto.com.br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"Person","@id":"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/502ab8892631bb005d6da2269fe5a3a7","name":"Kico (Henrique Lobo Weissmann)","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/devkico.itexto.com.br\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dd6973d86a689bc63122b2e603f25be3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6973d86a689bc63122b2e603f25be3?s=96&d=mm&r=g","caption":"Kico (Henrique Lobo Weissmann)"},"sameAs":["https:\/\/x.com\/loboweissmann"],"url":"https:\/\/devkico.itexto.com.br\/?author=1"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/posts\/464"}],"collection":[{"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464"}],"version-history":[{"count":1,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions\/465"}],"wp:attachment":[{"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devkico.itexto.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}