/** * Send. * * @param mail the mail * @throws Exception the exception */ public void send(Mail mail) throws Exception { this.mail = mail; Session session = Session.getInstance( mailProperties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } }); session.setDebug(true); MailMessage message; if (mail.getAttachment() == null || mail.getAttachment().isEmpty()) { message = new MailMessage( session, this.smtpUsername, mail.getRecipient(), mail.getSubject(), mail.getContent()); } else { message = new MailMessage( session, this.smtpUsername, mail.getRecipient(), mail.getSubject(), mail.getContent(), mail.getAttachment()); } Transport transport = session.getTransport(this.transportType); transport.connect(this.smtpHost, this.smtpPort, this.smtpUsername, this.smtpPassword); transport.sendMessage(message, message.getAllRecipients()); System.out.println("MailMessage was succesfuly sent."); transport.close(); }