Guest User

Untitled

a guest
Nov 19th, 2017
1,215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package com.coderesolutions;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.mail.Message;
  6. import javax.mail.MessagingException;
  7. import javax.mail.PasswordAuthentication;
  8. import javax.mail.Session;
  9. import javax.mail.Transport;
  10. import javax.mail.internet.InternetAddress;
  11. import javax.mail.internet.MimeMessage;
  12.  
  13. import org.junit.Ignore;
  14.  
  15. public class MailTest extends AbstractIntegrationTest {
  16.  
  17. @org.junit.Test
  18. @Ignore
  19. public void test() {
  20.  
  21.  
  22. Properties props = new Properties();
  23. props.put("mail.smtp.host", "mail.smtp.com");
  24. props.put("mail.smtp.socketFactory.port", "465");
  25. props.put("mail.smtp.socketFactory.class",
  26. "javax.net.ssl.SSLSocketFactory");
  27. props.put("mail.smtp.auth", "true");
  28. props.put("mail.smtp.port", "465");
  29.  
  30. Session session = Session.getDefaultInstance(props,
  31. new javax.mail.Authenticator() {
  32. protected PasswordAuthentication getPasswordAuthentication() {
  33. return new PasswordAuthentication("mailFrom@mail.com","password");
  34. }
  35. });
  36.  
  37. try {
  38.  
  39. Message message = new MimeMessage(session);
  40. message.setFrom(new InternetAddress("fromMail@mail.com"));
  41. message.setRecipients(Message.RecipientType.TO,
  42. InternetAddress.parse("receipient@mail.com"));
  43. message.setSubject("Testing Subject");
  44. message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!");
  45.  
  46. Transport.send(message);
  47.  
  48. System.out.println("Done");
  49.  
  50. } catch (MessagingException e) {
  51. throw new RuntimeException(e);
  52. }
  53.  
  54. }
  55.  
  56.  
  57. }
Add Comment
Please, Sign In to add comment