{"id":1540,"date":"2016-10-03T17:47:42","date_gmt":"2016-10-03T15:47:42","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1540"},"modified":"2017-05-11T10:51:27","modified_gmt":"2017-05-11T08:51:27","slug":"java-sendmail","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1540","title":{"rendered":"Java &#8211; sendmail"},"content":{"rendered":"<h1>Dependencies<\/h1>\n<p>If you use maven, add this to your pom.xml :<\/p>\n<pre lang=\"xml\">\r\n<dependency>\r\n  <groupId>org.apache.commons<\/groupId>\r\n  <artifactId>commons-email<\/artifactId>\r\n  <version>${common-email.version}<\/version>\r\n<\/dependency>\r\n<\/pre>\n<h1>Send an email<\/h1>\n<pre lang=\"java\">\r\n\/\/ Parameters :\r\nString smtpHost = \"localhost\";\r\nint smtpPort    = 587;\r\nboolean smtpIsSecure    = true;\r\n\t\t\r\nString emailFrom = \"emailFrom@example.com\";\r\nString emailTo = \"emailTo@example.com\";\r\nString emailSubject = \"subject\";\r\nString emailMessage = \"Hello world !\";\r\n\r\n\/\/ send email :\r\nEmail email = new SimpleEmail();\r\n\t\t\r\nif(smtpIsSecure){\t\t\t\r\n  email.setSslSmtpPort(properties.getProperty(SMTP_PORT));\r\n}\r\nelse {\r\n  email.setSmtpPort(smtpPort);\t\r\n}\r\n\r\nemail.setHostName(smtpHost);\t\t\r\nemail.setAuthenticator(new DefaultAuthenticator(\"SMTP_USERNAME\", \"SMTP_PASSWORD\"));\r\nemail.setSSLOnConnect(smtpIsSecure);\r\nemail.setFrom(emailFrom);\r\nemail.setSubject(emailSubject);\r\nemail.setMsg(emailMessage);\r\nemail.addTo(emailTo);\r\nemail.send();\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dependencies If you use maven, add this to your pom.xml : org.apache.commons commons-email ${common-email.version} Send an email \/\/ Parameters : String smtpHost = &#8220;localhost&#8221;; int smtpPort = 587; boolean smtpIsSecure = true; String emailFrom = &#8220;emailFrom@example.com&#8221;; String emailTo = &#8220;emailTo@example.com&#8221;; String emailSubject = &#8220;subject&#8221;; String emailMessage = &#8220;Hello world !&#8221;; \/\/ send email : Email [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1538,"menu_order":14,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1540","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1540"}],"version-history":[{"count":5,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1540\/revisions"}],"predecessor-version":[{"id":1968,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1540\/revisions\/1968"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1538"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}