{"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\/ja\/access-smtp-server-how-can-i-authenticate-mail-whatever-i-am-sending-with-the-smtp-server\/","title":{"rendered":"SMTP\u30b5\u30fc\u30d0\u30fc\u3078\u306e\u30a2\u30af\u30bb\u30b9 - smtp\u30b5\u30fc\u30d0\u30fc\u3067\u9001\u4fe1\u3059\u308b\u30e1\u30fc\u30eb\u3092\u8a8d\u8a3c\u3059\u308b\u306b\u306f\uff1f"},"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(&quot;mail.smtp.auth&quot;, &quot;true&quot;); <\/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    Message 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>Disclaimer &#8211; The Views Expressed In This Article Are Provided By A 3rd Party And May Not Match Those Of Our Website<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you use JavaMail api provided by Sun then you can get the latest api from Sun Downloads. JavaMail uses properties to load all configuration to the program. You must specify: # The hostname or IP address of your SMTP server mail.smtp.host=smtp.duke.java.sun.com # You get lots of debugging information if # this is turned on. Comment this line to turn # it off. mail.debug=true # The To email address ttapr2004.to=duke@duke.java.sun.com # The From email address ttapr2004.from=duke@j2ee_fanclub.java.su&#8230; You can easily connect without authenticate to the SMTP server. But you may experience that you cannot send email from your java program: 1. Your ip may be blocked by firewall to Access SMTP <a href=\"https:\/\/www.smtp-server.net\/ja\/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>[&hellip;]<\/a><\/p>\n","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\/ja\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/posts\/65\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.smtp-server.net\/ja\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}