Guest User

Untitled

a guest
Oct 31st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5.  
  6. import javax.mail.internet.MimeMessage.RecipientType;
  7.  
  8. import org.apache.commons.io.IOUtils;
  9. import org.codemonkey.simplejavamail.Email;
  10. import org.codemonkey.simplejavamail.Mailer;
  11. import org.codemonkey.simplejavamail.TransportStrategy;
  12.  
  13.  
  14. public class MyMailer {
  15.  
  16. /**
  17. * @param args
  18. * @throws IOException
  19. * @throws FileNotFoundException
  20. */
  21. public static void main(String[] args) throws FileNotFoundException, IOException
  22. {
  23.  
  24. final Email email = new Email();
  25.  
  26.  
  27. email.setFromAddress("Rakesh Waghela", "sender@gmail.com");
  28. email.setSubject("Hey testing Mail !");
  29. email.addRecipient("Java India" , "recipient@gmail.com" , RecipientType.TO);
  30. email.addRecipient("Sony Ujjwal", "anotheremail@gmail.com" , RecipientType.CC);
  31. email.setText("We should Meet up! ;)");
  32.  
  33. email.setTextHTML("<b>We should meet up for..!</b>" +
  34. "<br/>" +
  35. "<ol><li>Coffee</li><li>Milk</li></ol> ");
  36.  
  37.  
  38.  
  39. email.addEmbeddedImage("TestFile.jpg", IOUtils.toByteArray( new FileInputStream(new File("C://image.jpg"))), "image/jpeg");
  40.  
  41. new Mailer("smtp.gmail.com", 25, "myuserid@gmail.com", "mypassword",TransportStrategy.SMTP_TLS).sendMail(email);
  42.  
  43. }
  44. }
Add Comment
Please, Sign In to add comment