{"id":65,"date":"2016-02-26T09:52:12","date_gmt":"2016-02-26T09:52:12","guid":{"rendered":"http:\/\/www.smtp-server.net\/?p=65"},"modified":"2015-05-04T19:56:43","modified_gmt":"2015-05-04T19:56:43","slug":"access-smtp-server-how-can-i-authenticate-mail-whatever-i-am-sending-with-the-smtp-server","status":"publish","type":"post","link":"https:\/\/www.smtp-server.net\/el\/access-smtp-server-how-can-i-authenticate-mail-whatever-i-am-sending-with-the-smtp-server\/","title":{"rendered":"\u03a0\u03c1\u03cc\u03c3\u03b2\u03b1\u03c3\u03b7 \u03c3\u03c4\u03bf\u03bd \u03b4\u03b9\u03b1\u03ba\u03bf\u03bc\u03b9\u03c3\u03c4\u03ae SMTP - \u03c0\u03ce\u03c2 \u03bc\u03c0\u03bf\u03c1\u03ce \u03bd\u03b1 \u03c0\u03b9\u03c3\u03c4\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03c9 \u03c4\u03b7\u03bd \u03b1\u03c5\u03b8\u03b5\u03bd\u03c4\u03b9\u03ba\u03cc\u03c4\u03b7\u03c4\u03b1 \u03c4\u03bf\u03c5 \u03c4\u03b1\u03c7\u03c5\u03b4\u03c1\u03bf\u03bc\u03b5\u03af\u03bf\u03c5 \u03c0\u03bf\u03c5 \u03c3\u03c4\u03ad\u03bb\u03bd\u03c9 \u03bc\u03b5 \u03c4\u03bf\u03bd \u03b4\u03b9\u03b1\u03ba\u03bf\u03bc\u03b9\u03c3\u03c4\u03ae smtp;"},"content":{"rendered":"<p>If you use JavaMail api provided by Sun then you can get the latest api from Sun Downloads. <br \/>\nJavaMail uses properties to load all configuration to the program. <br \/>\nYou must specify: <br \/>\n# The hostname or IP address of your SMTP server <br \/>\n    mail.smtp.host=smtp.duke.java.sun.com <\/p>\n<p>    # You get lots of debugging information if <br \/>\n    # this is turned on. Comment this line to turn <br \/>\n    # it off. <br \/>\n    mail.debug=true <\/p>\n<p>    # The To email address <br \/>\n    ttapr2004.to=duke@duke.java.sun.com <\/p>\n<p>    # The From email address <br \/>\n    ttapr2004.from=duke@j2ee_fanclub.java.su&#8230; <\/p>\n<p>You can easily connect without authenticate to the SMTP server. But you may experience that you cannot send email from your java program: <br \/>\n1. Your ip may be blocked by firewall to <a href=\"http:\/\/www.cnn.com\/TECH\/computing\/9911\/04\/netwinder.idg\/index.html\" target=\"_blank\" rel=\"noopener\">Access SMTP Server<\/a> <br \/>\n2. Your SMTP server block senders address, to address and maybe your ip. <br \/>\n3. Your SMTP server requires authentication <\/p>\n<p>If your server requires authentication this  igot it from internet <br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8230; <br \/>\npublic class SendMailUsingAuthentication { <\/p>\n<p>  private static final String SMTP_HOST_NAME = &quot;myserver.smtphost.com&quot;; <br \/>\n  private static final String SMTP_AUTH_USER = &quot;myusername&quot;; <br \/>\n  private static final String SMTP_AUTH_PWD = &quot;mypwd&quot;; <\/p>\n<p>  private static final String emailMsgTxt = <br \/>\n      &quot;Online Order Confirmation Message. Also include the Tracking Number.&quot;; <br \/>\n  private static final String emailSubjectTxt = &quot;Order Confirmation Subject&quot;; <br \/>\n  private static final String emailFromAddress = &quot;sudhir@javacommerce.com&quot;; <\/p>\n<p>  \/\/ Add List of Email address to who email needs to be sent to <br \/>\n  private static final String[] emailList = { <br \/>\n      &quot;mark@yahoo.com&quot;, &quot;robin@javacommerce.com&quot;}; <\/p>\n<p>  public static void main(String args[]) throws Exception { <br \/>\n    SendMailUsingAuthentication smtpMailSender = new <br \/>\n        SendMailUsingAuthentication(); <br \/>\n    smtpMailSender.postMail(emailList, emailSubjectTxt, emailMsgTxt, <br \/>\n                            emailFromAddress); <br \/>\n    System.out.println(&quot;Sucessfully Sent mail to All Users&quot;); <br \/>\n  } <\/p>\n<p>  public void postMail(String recipients[], String subject, <br \/>\n                       String message, String from) throws MessagingException { <br \/>\n    boolean debug = false; <\/p>\n<p>    \/\/Set the host smtp address <br \/>\n    Properties props = new Properties(); <br \/>\n    props.put(&quot;mail.smtp.host&quot;, SMTP_HOST_NAME); <br \/>\n    props.put(\"mail.smtp.auth\", \"true\"),; <\/p>\n<p>    Authenticator auth = new SMTPAuthenticator(); <br \/>\n    Session session = Session.getDefaultInstance(props, auth); <\/p>\n<p>    session.setDebug(debug); <\/p>\n<p>    \/\/ create a message <br \/>\n    \u039c\u03ae\u03bd\u03c5\u03bc\u03b1 msg = new MimeMessage(session),; <\/p>\n<p>    \/\/ set the from and to address <br \/>\n    InternetAddress addressFrom = new InternetAddress(from); <br \/>\n    msg.setFrom(addressFrom); <\/p>\n<p>    InternetAddress[] addressTo = new InternetAddress[recipients.length]; <br \/>\n    for (int i = 0; i &lt; recipients.length; i++) { <br \/>\n      addressTo[i] = new InternetAddress(recipients[i]); <br \/>\n    } <br \/>\n    msg.setRecipients(Message.RecipientType&#8230;. addressTo); <\/p>\n<p>    \/\/ Setting the Subject and Content Type <br \/>\n    msg.setSubject(subject),; <br \/>\n    msg.setContent(message, &quot;text\/plain&quot;); <br \/>\n    Transport.send(msg),; <br \/>\n  } <\/p>\n<p>  \/** <br \/>\n   * SimpleAuthenticator is used to do simple authentication <br \/>\n   * when the SMTP server requires it. <br \/>\n   *\/ <br \/>\n  private class SMTPAuthenticator <br \/>\n      extends javax.mail.Authenticator { <\/p>\n<p>    public PasswordAuthentication getPasswordAuthentication() { <br \/>\n      String username = SMTP_AUTH_USER; <br \/>\n      String password = SMTP_AUTH_PWD; <br \/>\n      return new PasswordAuthentication(username, password),; <br \/>\n    } <br \/>\n  } <br \/>\n} <br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8230;<\/p>\n<p>\u0391\u03c0\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7 \u03b5\u03c5\u03b8\u03c5\u03bd\u03ce\u03bd - \u039f\u03b9 \u03b1\u03c0\u03cc\u03c8\u03b5\u03b9\u03c2 \u03c0\u03bf\u03c5 \u03b5\u03ba\u03c6\u03c1\u03ac\u03b6\u03bf\u03bd\u03c4\u03b1\u03b9 \u03c3\u03b5 \u03b1\u03c5\u03c4\u03cc \u03c4\u03bf \u03ac\u03c1\u03b8\u03c1\u03bf \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03bd\u03c4\u03b1\u03b9 \u03b1\u03c0\u03cc \u03ad\u03bd\u03b1 3\u03bf \u03bc\u03ad\u03c1\u03bf\u03c2 \u03ba\u03b1\u03b9 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03bc\u03b7\u03bd \u03c4\u03b1\u03b9\u03c1\u03b9\u03ac\u03b6\u03bf\u03c5\u03bd \u03bc\u03b5 \u03b5\u03ba\u03b5\u03af\u03bd\u03b5\u03c2 \u03c4\u03b7\u03c2 \u03b9\u03c3\u03c4\u03bf\u03c3\u03b5\u03bb\u03af\u03b4\u03b1\u03c2 \u03bc\u03b1\u03c2<\/p>","protected":false},"excerpt":{"rendered":"<p>\u0395\u03ac\u03bd \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03b5\u03af\u03c4\u03b5 \u03c4\u03bf JavaMail api \u03c0\u03bf\u03c5 \u03c0\u03b1\u03c1\u03ad\u03c7\u03b5\u03c4\u03b1\u03b9 \u03b1\u03c0\u03cc \u03c4\u03b7 Sun, \u03c4\u03cc\u03c4\u03b5 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af\u03c4\u03b5 \u03bd\u03b1 \u03bb\u03ac\u03b2\u03b5\u03c4\u03b5 \u03c4\u03bf \u03c4\u03b5\u03bb\u03b5\u03c5\u03c4\u03b1\u03af\u03bf api \u03b1\u03c0\u03cc \u03c4\u03bf Sun Downloads. \u03a4\u03bf JavaMail \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03b5\u03af \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03b3\u03b9\u03b1 \u03bd\u03b1 \u03c6\u03bf\u03c1\u03c4\u03ce\u03c3\u03b5\u03b9 \u03cc\u03bb\u03b5\u03c2 \u03c4\u03b9\u03c2 \u03c1\u03c5\u03b8\u03bc\u03af\u03c3\u03b5\u03b9\u03c2 \u03c3\u03c4\u03bf \u03c0\u03c1\u03cc\u03b3\u03c1\u03b1\u03bc\u03bc\u03b1. \u03a0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03ba\u03b1\u03b8\u03bf\u03c1\u03af\u03c3\u03b5\u03c4\u03b5: # \u03a4\u03bf \u03cc\u03bd\u03bf\u03bc\u03b1 \u03ba\u03b5\u03bd\u03c4\u03c1\u03b9\u03ba\u03bf\u03cd \u03c5\u03c0\u03bf\u03bb\u03bf\u03b3\u03b9\u03c3\u03c4\u03ae \u03ae \u03c4\u03b7 \u03b4\u03b9\u03b5\u03cd\u03b8\u03c5\u03bd\u03c3\u03b7 IP \u03c4\u03bf\u03c5 \u03b4\u03b9\u03b1\u03ba\u03bf\u03bc\u03b9\u03c3\u03c4\u03ae SMTP mail.smtp.host=smtp.duke.java.sun.com # \u039c\u03c0\u03bf\u03c1\u03b5\u03af\u03c4\u03b5 \u03bd\u03b1 \u03bb\u03ac\u03b2\u03b5\u03c4\u03b5 \u03c0\u03bf\u03bb\u03bb\u03ad\u03c2 \u03c0\u03bb\u03b7\u03c1\u03bf\u03c6\u03bf\u03c1\u03af\u03b5\u03c2 \u03b5\u03bd\u03c4\u03bf\u03c0\u03b9\u03c3\u03bc\u03bf\u03cd \u03c3\u03c6\u03b1\u03bb\u03bc\u03ac\u03c4\u03c9\u03bd \u03b1\u03bd # \u03b1\u03c5\u03c4\u03cc \u03b5\u03af\u03bd\u03b1\u03b9 \u03b5\u03bd\u03b5\u03c1\u03b3\u03bf\u03c0\u03bf\u03b9\u03b7\u03bc\u03ad\u03bd\u03bf. <a href=\"https:\/\/www.smtp-server.net\/el\/access-smtp-server-how-can-i-authenticate-mail-whatever-i-am-sending-with-the-smtp-server\/\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Access SMTP Server &#8211; how can i authenticate mail  whatever i am sending with the smtp server?<\/span>[...]<\/a><\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-smtp-questions"],"_links":{"self":[{"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/posts\/65\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.smtp-server.net\/el\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}