Posts

SMTP Implementation with SSL/TLS

Image
There are many ways to implement in java, But mostly used are javax.mail api provided by java and apache commons-net jar . I personally preferred commons-net over java API as it simplify the implementation as it builds on java api. (see below link) Only Difference between Simple mail and TLS mail is to provide encrypted channel between to sender-server to mail-server Commons-net Implementation of SMTP with TLS public class CommonsNetSMTP { //Mail-Server public static final String SMTP_SERVER_ADDRESS = "mail-server"; // SSL/TLS Port; can be different according to server public static final int SMTP_PORT = 587; // Sender Mail-Address public static final String FROM = "from@domain.com"; // Receiver Mail-Address public static final String TO = "to@domain.com"; // Subject of email public static final String SUBJECT = "subject"; // Body of email public static final String BODY = "bod

Context Reuse : Pass the executable code as Parameter to methods : JAVA 8

Context Reuse  Context reuse is a special kind of code reusability. Context reuse is the reuse of Set of Instructions while various different actions take place in between. Following are the steps to understand context reuse: Before Block  ( Fixed set of Instruction) Your action or code you want to execute After Block  (fixed set of instruction) Consider the Scenario: Two different methods want to use inputStream :  Method 1: write the InputStream to stdout Method 2: read the input stream to String and return the Object. See the implementation public void printStream(InputStream inputStream) throws IOException { if(inputStream == null) return; IOException exception = null; try{ int character = inputStream.read(); while(character != -1){ System.out.print((char) character); character = inputStream.read(); } } finally { try{ inputStream.close();