mailhost.StartApp.java Source code

Java tutorial

Introduction

Here is the source code for mailhost.StartApp.java

Source

package mailhost;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang3.StringUtils;

public class StartApp {

    private String to = null;
    private String subject = "";
    private String body = "";
    private String mailhost = "mailhost";

    public static void main(String[] args) {

        System.out.println("START TEST 1");

        String weights = "", cube = "";
        Integer b = null;
        weights = weights + b != null ? "" + b : "" + ",";
        System.out.println((weights + b != null ? "" + b : "@"));
        System.out.println(StringUtils.isBlank(weights));
        System.out.println(StringUtils.isBlank(weights) ? "0" : weights);

        /*StartApp s = new StartApp();
        s.to = "vkhanna@matson.com";//args[0];
        s.subject = "mailhost Test";
        // s.body = "This is a java test. <b>This app tries to send email</b> via mailhost.";
        s.body =  s.createContentForPOVConfirmation();
            
            
        try {
          s.sendEmail(s.to,s.subject,s.body );
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MessagingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }*/
    }

    public void sendEmail(String to, String subject, String body)
            throws UnsupportedEncodingException, MessagingException {

        System.out.println(String.format("Sending notification email recipients " + "to  " + to + " subject  "
                + subject + "host " + mailhost));

        if (StringUtils.isBlank(to))
            throw new IllegalArgumentException("The email request should have at least one recipient");

        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host", mailhost);

        Session session = Session.getDefaultInstance(properties);
        Address[] a = new InternetAddress[1];
        a[0] = new InternetAddress("test@matson.com");

        MimeMessage message = new MimeMessage(session);

        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.addFrom(a);

        message.setSubject(subject);
        message.setContent(body, "text/html; charset=utf-8");
        //message.setText(body);

        // Send message
        Transport.send(message);
        System.out.println("Email sent.");
    }

    /*public void sendHtml(String from, String to, String subject, String content, EmailAttachment attachment) {
     System.out.println("<--- START SEND METHOD sendHtml ---> ");
     MimeMessage message = mailSender.createMimeMessage();
        
     try {
        System.out.println("Mail sent from ---> "+from);
        System.out.println("Original mail recipient ---> "+to);
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(from);
        //convert emails to String[]
            
        if(to!=null){
           if (to.contains(";")) {
              String recipients[] = to.split(";");
              System.out.println("email address :"+recipients);
              helper.setTo(recipients);
           }
           else if(to.contains(","))
           {
              String recipients[] = to.split(",");
              System.out.println("email address :"+recipients);
              helper.setTo(recipients);
           }else{
              helper.setTo(to);
           }
        }
            
        helper.setSubject(subject);
            
        helper.setText(content,true);
            
        if(null != attachment){
           helper.addAttachment(attachment.getName(), attachment.getFile());
        }
     } catch (MessagingException me) {
        System.out.println("TechnicalException: ---> "+me);
     }
     mailSender.send(message);
     System.out.println("MAIL SENT SUCCESSFULLY");
    }*/
    public String createContentForPOVConfirmation() {
        ///String newLine = System.getProperty("line.separator");
        String newLine = "<br>";
        StringBuffer stringBuffer = new StringBuffer();
        boolean isAlaska = false;

        if (!isAlaska) {
            stringBuffer.append("Thank you for shipping with Matson!");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("For your convenience we have attached a booking confirmation. You can");
            stringBuffer.append(newLine);
            stringBuffer.append("always track the shipment status of your vehicle at");
            stringBuffer.append(newLine);
            stringBuffer.append("https://www.matson.com/vcsc/pov/tracking/tracking.jsp");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append(
                    "<b>**AVAILABILITY** Availability is estimated to be between 2-3 weeks. The vessel voyage listed on this booking confirmation does not guarantee the auto will sail on that specific vessel voyage. Guaranteed delivery can be provided only using our PREMIUM Service.</b>");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("Please review the checklist below and ensure you are in compliance as");
            stringBuffer.append(newLine);
            stringBuffer.append("you prepare your vehicle for shipment.  If you have any questions, you can");
            stringBuffer.append(newLine);
            //stringBuffer.append("reach us by email at: pov_assistance@matson.com or call our service");
            stringBuffer.append("reach us by email at: ");
            stringBuffer.append("email@matson.com");
            stringBuffer.append(" or by phone at: ");
            //stringBuffer.append(newLine);
            //stringBuffer.append("center at: 1-800-4-MATSON (800-462-8766).");
            //stringBuffer.append("center at: ");
            stringBuffer.append("6823689");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("SHIPPING CHECKLIST");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("Please ensure that:");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("- Your vehicle/s is in operating condition, with a working emergency");
            stringBuffer.append(newLine);
            stringBuffer.append("brake,");
            stringBuffer.append(newLine);
            stringBuffer.append(" and is licensed or qualified to be licensed for operation on public");
            stringBuffer.append(newLine);
            stringBuffer.append(" streets or highways");
            stringBuffer.append(newLine);
            stringBuffer.append("- The vehicle is washed");
            stringBuffer.append(newLine);
            stringBuffer.append("- Personal belongings are removed");
            stringBuffer.append(newLine);
            stringBuffer.append("- There are no cracks in windshields or other windows");
            stringBuffer.append(newLine);
            stringBuffer.append("- The gas tank is less than a 1/4 tank full");
            stringBuffer.append(newLine);
            stringBuffer.append("- You remove fire extinguishers");
            stringBuffer.append(newLine);
            stringBuffer.append("- Propane tanks are empty");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("In addition to the above, for EASTBOUND SHIPMENTS, please make sure");
            stringBuffer.append(newLine);
            stringBuffer.append("that:");
            stringBuffer.append(newLine);
            stringBuffer.append("- You bring the certificate of ownership and a current certificate");
            stringBuffer.append(newLine);
            stringBuffer.append("  of registration *");
            stringBuffer.append(newLine);
            stringBuffer.append("- If someone other than the registered owner delivers the automobile,");
            stringBuffer.append(newLine);
            stringBuffer.append("  Matson is provided a notarized letter of authorization from the");
            stringBuffer.append(newLine);
            stringBuffer.append("registered owner(s)");
            stringBuffer.append(newLine);
            stringBuffer.append(" authorizing shipment. If a lien holder is named on the title or");
            stringBuffer.append(newLine);
            stringBuffer.append(" registration, then a letter from the lien holder authorizing shipment");
            stringBuffer.append(newLine);
            stringBuffer.append("from");
            stringBuffer.append(newLine);
            stringBuffer.append(" Hawaii, Guam, Saipan or Micronesia is required * please note that a");
            stringBuffer.append(newLine);
            stringBuffer.append("letter from the lien");
            stringBuffer.append(newLine);
            stringBuffer.append(" holder does not have to be notarized.");
            stringBuffer.append(newLine);
            stringBuffer.append("- The current vehicle registration is provided");
            stringBuffer.append(newLine);
            stringBuffer.append("- Any copies of Title or Registration include the front and back of the");
            stringBuffer.append(newLine);
            stringBuffer.append("  original Document");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("PLEASE NOTE - Vehicles shipping from HAWAII to the MAINLAND UNITED");
            stringBuffer.append(newLine);
            stringBuffer.append("STATES");
            stringBuffer.append(newLine);
            stringBuffer.append("are subject to stringent inspections by the USDA prior to shipping.  It");
            stringBuffer.append(newLine);
            stringBuffer.append("is the responsibility");
            stringBuffer.append(newLine);
            stringBuffer.append("of the shipper to have the interior and exterior of the vehicle");
            stringBuffer.append(newLine);
            stringBuffer.append("thoroughly cleaned.");
            stringBuffer.append(newLine);
            stringBuffer.append("Example: The USDA looks for clumps of mud in wheel wells or under the");
            stringBuffer.append(newLine);
            stringBuffer.append("vehicle's");
            stringBuffer.append(newLine);
            stringBuffer.append("carriage, under the hood of vehicles is also inspected, the USDA also");
            stringBuffer.append(newLine);
            stringBuffer.append("   looks for dirt,");
            stringBuffer.append(newLine);
            stringBuffer.append("grass, plant seeds in the interior as well as the exterior and for");
            stringBuffer.append(newLine);
            stringBuffer.append("anything that they consider");
            stringBuffer.append(newLine);
            stringBuffer.append("   invasive to the U.S Continent.  If you fail the USDA inspection Matson");
            stringBuffer.append(newLine);
            stringBuffer.append("   will be unable to");
            stringBuffer.append(newLine);
            stringBuffer.append("ship your vehicle until the vehicle has been properly cleaned and");
            stringBuffer.append(newLine);
            stringBuffer.append("re-inspected by the USDA.");
            stringBuffer.append(newLine);
            stringBuffer.append(newLine);
            stringBuffer.append("Matson reserves the right to reject receipt of cargo if the cargo does");
            stringBuffer.append(newLine);
            stringBuffer.append("not meet the");
            stringBuffer.append(newLine);
            stringBuffer.append("requirements for safe transportation and handling by our stevedore or");
            stringBuffer.append(newLine);
            stringBuffer.append("   vessel operations.");
            stringBuffer.append(newLine);
            stringBuffer.append("* - Active military members with out-of-state lien holders are exempt");
            stringBuffer.append(newLine);
            stringBuffer.append("from this requirement");
        } else {
            stringBuffer.append(newLine);
            stringBuffer.append(
                    "For your convenience we have attached a booking confirmation.  You can track the location of your vehicle at https://www.matson.com/vcsc/pov/tracking.jsp.");
            stringBuffer.append(newLine);

            stringBuffer.append(newLine);
            //stringBuffer.append("Please review the checklist below and ensure you are in compliance as you prepare your vehicle for shipment.  If you have questions you can reach up by email at alaskacs@matson.com or call our customer service department at 1-877-678-7447");
            stringBuffer.append(
                    "Please review the checklist below and ensure you are in compliance as you prepare your vehicle for shipment.  If you have any questions, you can reach us by email at: ");
            stringBuffer.append("email@matson.com");
            stringBuffer.append(" or by phone at: ");
            stringBuffer.append("7794830");
            stringBuffer.append(newLine);

            stringBuffer.append(newLine);

            stringBuffer.append(newLine);
            stringBuffer.append("Shipping Checklist");
            stringBuffer.append(newLine);

            stringBuffer.append(newLine);
            stringBuffer.append("Please ensure:-");
            stringBuffer.append(newLine);
            stringBuffer.append(
                    "Your vehicle is in operating condition, with a working emergency break, is licensed or qualified to be licensed for operation on public streets and highways.");
            stringBuffer.append(newLine);
            stringBuffer.append("The vehicle has been washed.");
            stringBuffer.append(newLine);
            stringBuffer.append("There are no cracks or chips in the windshield or any other windows.");
            stringBuffer.append(newLine);
            stringBuffer.append("The gas tank is less than a  tank full.");
            stringBuffer.append(newLine);
            stringBuffer.append("Fire extinguishers and/or propane tanks are removed.");
            stringBuffer.append(newLine);
            stringBuffer.append("Shipping personal belongings in the vehicle  please contact customer service.");
            stringBuffer.append(newLine);

            stringBuffer.append(newLine);
            stringBuffer.append("In addition to the above, for ALL shipments to and from Alaska please ensure:-");
            stringBuffer.append(newLine);
            stringBuffer.append(
                    "You bring the Certificate of Ownership (Title) and a current Certificate of Registration.");
            stringBuffer.append(newLine);
            stringBuffer.append(
                    "If someone other than the registered owner(s) delivers the vehicle, Matson requires that a notarized letter of authorization from the registered owner(s) is provided.");
            stringBuffer.append(newLine);
            /*stringBuffer.append("*If a Lien Holders name is listed on the Title or Registration, a letter from the Lien Holder is required authorizing the shipment from the State of Alaska.");
            stringBuffer.append(newLine);
            stringBuffer.append("All copies of the Title and Registration must include the front and back of the original document.");
            stringBuffer.append(newLine);
            stringBuffer.append("*Active Duty Military Personnel with out of state Lien Holders are exempt from this requirement.");
            stringBuffer.append(newLine);*/

            stringBuffer.append(newLine);
            stringBuffer.append(
                    "Matson reserves the right to reject receipt of cargo if the cargo does not meet the requirements for safe transportation and handling by Terminal or Vessel Operations Personnel.");
        }

        return stringBuffer.toString();
    }

}