Advertisement
Guest User

Send Mail with JAVA

a guest
Nov 26th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Properties;
  2. import javax.mail.Message;
  3. import javax.mail.MessagingException;
  4. import javax.mail.PasswordAuthentication;
  5. import javax.mail.Session;
  6. import javax.mail.Transport;
  7. import javax.mail.internet.InternetAddress;
  8. import javax.mail.internet.MimeMessage;
  9.  
  10. public class SimpleMailSender {
  11.     public static void main(String[] args) {
  12.         Properties props = new Properties();
  13.         props.put("mail.smtp.host", "smtp.gmail.com");
  14.         props.put("mail.smtp.socketFactory.port", "465");
  15.         props.put("mail.smtp.socketFactory.class",
  16.                 "javax.net.ssl.SSLSocketFactory");
  17.         props.put("mail.smtp.auth", "true");
  18.         props.put("mail.smtp.port", "465");
  19.  
  20.         Session session = Session.getDefaultInstance(props,
  21.             new javax.mail.Authenticator() {
  22.                 protected PasswordAuthentication getPasswordAuthentication() {
  23.                     return new PasswordAuthentication("ce.umitunal@gmail.com","  tvljswywbozgfrlu  ");
  24.                 }
  25.             });
  26.  
  27.         try {
  28.  
  29.             Message message = new MimeMessage(session);
  30.             message.setFrom(new InternetAddress("ce.umitunal@gmail.com"));
  31.             message.setRecipients(Message.RecipientType.TO,
  32.                     InternetAddress.parse("emrah.yilmaz@konatus.tv"));
  33.             message.setSubject("Hacý Test Maili Bu");
  34.             message.setText("Ben ümit Ünal Testingen ! ," +
  35.                     "\n\n No spam to my email, please!");
  36.  
  37.             Transport.send(message);
  38.  
  39.             System.out.println("Done");
  40.  
  41.         } catch (MessagingException e) {
  42.             throw new RuntimeException(e);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement