Advertisement
Guest User

Untitled

a guest
May 27th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package mail;
  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. public class SendMailTLS {
  14.  
  15.  
  16. public static void main(String[] args) {
  17. //posljiEmail("jan.ficko@gmail.com", "Jan Ficko", "Potrdilo o nakupu", "Sporocamo vam da je vas nakup bil izveden uspesno");
  18. }
  19.  
  20.  
  21. public static void posljiEmail(String prejemnik, String naziv, String subjekt, String tekst){
  22.  
  23. final String username = "lekarnaferi@gmail.com";
  24. final String password = "janficko";
  25.  
  26. Properties props = new Properties();
  27. props.put("mail.smtp.auth", "true");
  28. props.put("mail.smtp.starttls.enable", "true");
  29. props.put("mail.smtp.host", "smtp.gmail.com");
  30. props.put("mail.smtp.port", "587");
  31.  
  32. Session session = Session.getInstance(props,
  33. new javax.mail.Authenticator() {
  34. protected PasswordAuthentication getPasswordAuthentication() {
  35. return new PasswordAuthentication(username, password);
  36. }
  37. });
  38.  
  39. try {
  40.  
  41.  
  42.  
  43. Message message = new MimeMessage(session);
  44. message.setFrom(new InternetAddress("lekarnaferi@gmail.com"));
  45. message.setRecipients(Message.RecipientType.TO,
  46. InternetAddress.parse(prejemnik));
  47. message.setSubject(subjekt);
  48. message.setContent(tekst, "text/html; charset=UTF-8");
  49. Transport.send(message);
  50.  
  51. System.out.println("Done");
  52.  
  53. } catch (MessagingException e) {
  54. throw new RuntimeException(e);
  55. }
  56.  
  57. }
  58.  
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement