daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Jun 21st, 2015 233 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package common.util.email;
  7.  
  8. /**
  9.  *
  10.  * @author rrodriguez
  11.  */
  12. import java.util.Properties;
  13.  
  14. import javax.mail.Message;
  15. import javax.mail.MessagingException;
  16. import javax.mail.PasswordAuthentication;
  17. import javax.mail.Session;
  18. import javax.mail.Transport;
  19. import javax.mail.internet.InternetAddress;
  20. import javax.mail.internet.MimeMessage;
  21.  
  22. public class SendMailTLS {
  23.  
  24.                 public static void main(String[] args) {
  25.  
  26.                 final String username = "roberto@roberto-blog.com";
  27.                 final String password = "Hocuspocus1";
  28. //
  29. //              final String username = "username@gmail.com";
  30. //              final String password = "password";
  31.  
  32.                 Properties props = new Properties();
  33.                 props.put("mail.smtp.auth", "true");
  34.                 props.put("mail.smtp.starttls.enable", "true");
  35.                 props.put("mail.smtp.host", "mail.roberto-blog.com");
  36.                 props.put("mail.smtp.ssl.trust", "smtpserver");
  37.                 props.put("mail.smtp.port", "587");
  38.  
  39.                 Session session = Session.getInstance(props,
  40.                   new javax.mail.Authenticator() {
  41.                         protected PasswordAuthentication getPasswordAuthentication() {
  42.                                 return new PasswordAuthentication(username, password);
  43.                         }
  44.                   });
  45.  
  46.                 try {
  47.  
  48.                         Message message = new MimeMessage(session);
  49.                         message.setFrom(new InternetAddress("roberto@roberto-blog.com"));
  50.                         message.setRecipients(Message.RecipientType.TO,
  51.                                 InternetAddress.parse("titorobe@yahoo.com"));
  52.                         message.setSubject("Testing Subject");
  53.                         message.setText("Dear Mail Crawler,"
  54.                                 + "\n\n No spam to my email, please!");
  55.  
  56.                         Transport.send(message);
  57.  
  58.                         System.out.println("Done");
  59.  
  60.                 } catch (MessagingException e) {
  61.                         throw new RuntimeException(e);
  62.                 }
  63.         }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top