{"id":556,"date":"2017-06-28T00:49:49","date_gmt":"2017-06-28T01:19:49","guid":{"rendered":"http:\/\/www.mind4y.co\/itstuff\/2017\/06\/28\/java-mail-2\/"},"modified":"2020-03-19T23:28:48","modified_gmt":"2020-03-19T23:58:48","slug":"java-mail-2","status":"publish","type":"post","link":"https:\/\/ultering.com\/it4us\/?p=556","title":{"rendered":"JAVA: MAIL"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\">\r\n<!-- https:\/\/mvnrepository.com\/artifact\/javax.mail\/javax.mail-api -->\r\n<dependency>\r\n    <groupId>javax.mail<\/groupId>\r\n    <artifactId>javax.mail-api<\/artifactId>\r\n    <version>1.5.6<\/version>\r\n<\/dependency>\r\n<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\nclass Mailer{  \r\n    Properties props = new Properties();    \r\n    public Mailer(){\r\n          props.put(\"mail.smtp.host\", \"smtp.gmail.com\");    \r\n          props.put(\"mail.smtp.socketFactory.port\", \"465\");    \r\n          props.put(\"mail.smtp.socketFactory.class\",    \r\n                    \"javax.net.ssl.SSLSocketFactory\");    \r\n          props.put(\"mail.smtp.auth\", \"true\");    \r\n          props.put(\"mail.smtp.port\", \"465\");\r\n    }\r\n\r\n    public static void send(final String from,final String password,String to,String sub,String msg){  \r\n          \/\/get Session   \r\n          Session session = Session.getDefaultInstance(props,    \r\n           new javax.mail.Authenticator() {    \r\n           protected PasswordAuthentication getPasswordAuthentication() {    \r\n           return new PasswordAuthentication(from,password);  \r\n           }    \r\n          });    \r\n          \/\/compose message    \r\n          try {    \r\n           MimeMessage message = new MimeMessage(session);    \r\n           message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));    \r\n           message.setSubject(sub);    \r\n           message.setText(msg);    \r\n           \/\/send message  \r\n           Transport.send(message);    \r\n           System.out.println(\"message sent successfully\");    \r\n          } catch (MessagingException e) {throw new RuntimeException(e);}    \r\n             \r\n    }  \r\n}  \r\n<\/pre>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>javax.mail javax.mail-api 1.5.6 class Mailer{ Properties props = new Properties(); public Mailer(){ props.put(&#8220;mail.smtp.host&#8221;, &#8220;smtp.gmail.com&#8221;); props.put(&#8220;mail.smtp.socketFactory.port&#8221;, &#8220;465&#8221;); props.put(&#8220;mail.smtp.socketFactory.class&#8221;, &#8220;javax.net.ssl.SSLSocketFactory&#8221;); props.put(&#8220;mail.smtp.auth&#8221;, &#8220;true&#8221;); props.put(&#8220;mail.smtp.port&#8221;, &#8220;465&#8221;); } public static void send(final String from,final String password,String to,String sub,String msg){ \/\/get Session Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from,password); } }); \/\/compose message try &#8230; <a href=\"https:\/\/ultering.com\/it4us\/?p=556\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;JAVA: MAIL&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[12],"tags":[15,13,16],"class_list":["post-556","post","type-post","status-publish","format-standard","hentry","category-java","tag-email","tag-java","tag-mail"],"_links":{"self":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=556"}],"version-history":[{"count":1,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/556\/revisions"}],"predecessor-version":[{"id":2650,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/556\/revisions\/2650"}],"wp:attachment":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}