List of usage examples for javax.mail.internet MimeMessage addHeader
@Override public void addHeader(String name, String value) throws MessagingException
From source file:ee.cyber.licensing.service.MailService.java
public void sendExpirationNearingMail(License license) throws IOException, MessagingException { logger.info("1st ===> setup Mail Server Properties"); Properties mailServerProperties = getProperties(); final String email = mailServerProperties.getProperty("fromEmail"); final String password = mailServerProperties.getProperty("password"); final String host = mailServerProperties.getProperty("mail.smtp.host"); final String mailTo = mailServerProperties.getProperty("mailTo"); logger.info("2nd ===> create Authenticator object to pass in Session.getInstance argument"); Authenticator authentication = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(email, password); }//from ww w .ja va 2 s. c o m }; logger.info("Mail Server Properties have been setup successfully"); logger.info("3rd ===> get Mail Session.."); Session getMailSession = Session.getInstance(mailServerProperties, authentication); logger.info("4th ===> generateAndSendEmail() starts"); MimeMessage mailMessage = new MimeMessage(getMailSession); mailMessage.addHeader("Content-type", "text/html; charset=UTF-8"); mailMessage.addHeader("format", "flowed"); mailMessage.addHeader("Content-Transfer-Encoding", "8bit"); mailMessage.setFrom(new InternetAddress(email, "Licensing service")); mailMessage.setSubject("License with id " + license.getId() + " is expiring"); mailMessage.setSentDate(new Date()); mailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo)); String emailBody = "This is test<br><br> Regards, <br>Licensing team"; mailMessage.setContent(emailBody, "text/html"); logger.info("5th ===> Get Session"); sendMail(email, password, host, getMailSession, mailMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testBccMessage() throws IOException, MessagingException, InterruptedException { MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject dav"); mimeMessage.setText("Test message"); sendAndCheckMessage(mimeMessage, Settings.getProperty("davmail.bcc")); }
From source file:davmail.smtp.TestSmtp.java
public void testSendSimpleMessage() throws IOException, MessagingException, InterruptedException { String body = "Test message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body);//from ww w . j a va2s . c om sendAndCheckMessage(mimeMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testDotMessage() throws IOException, MessagingException, InterruptedException { String body = "First line\r\n.\r\nSecond line"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body);//from w ww .j a v a2s.c o m sendAndCheckMessage(mimeMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testComplexToMessage() throws IOException, MessagingException, InterruptedException { String body = "Test message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", "nickname <" + Settings.getProperty("davmail.to") + '>'); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body);/*from w ww . j a v a 2 s . c om*/ sendAndCheckMessage(mimeMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testSendPlainTextMessage() throws IOException, MessagingException, InterruptedException { String body = "Test plain text message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test text/plain message"); mimeMessage.setText(body);/*from ww w . j a v a 2s . co m*/ sendAndCheckMessage(mimeMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testSendHtmlMessage() throws IOException, MessagingException, InterruptedException { String body = "Test html message <font color=\"#ff0000\">red</font>"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test html message"); mimeMessage.setContent(body, "text/html"); sendAndCheckMessage(mimeMessage);/*from ww w . ja va2s . com*/ }
From source file:davmail.smtp.TestSmtp.java
public void testInvalidFrom() throws IOException, MessagingException, InterruptedException { String body = "Test message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("From", "guessant@loca.net"); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body);/*from ww w.j a va2 s.c o m*/ sendAndCheckMessage(mimeMessage, "guessant@loca.net", null); }
From source file:davmail.smtp.TestSmtp.java
public void testSendMessage() throws IOException, MessagingException, InterruptedException { String body = "Test message\r\n" + "Special characters: \r\n" + "Chinese: " + ((char) 0x604F) + ((char) 0x7D59); MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body, "UTF-8"); sendAndCheckMessage(mimeMessage);//from w ww. j a v a2s. c o m }
From source file:davmail.smtp.TestSmtp.java
public void testSendMessageTwice() throws IOException, MessagingException, InterruptedException { Settings.setProperty("davmail.smtpCheckDuplicates", "true"); String body = "First line\r\n.\r\nSecond line"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body);// w w w .j a v a 2 s . c om sendAndCheckMessage(mimeMessage); sendAndCheckMessage(mimeMessage); }