Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public class Sendmail{
  2. static String success="";
  3. public static String sendMail(String to,String subject,String content)
  4. {
  5.  
  6. //JOptionPane.showMessageDialog(null, "inside"+to);
  7. final String username = "keepitsimplesafe@gmail.com";
  8. final String password = "keepitsimple";
  9. //String sub=subject;
  10. //String cont=content;
  11. Properties props = new Properties();
  12.  
  13. props.put("mail.smtp.auth", "true");
  14. props.put("mail.smtp.starttls.enable", "true");
  15. props.put("mail.smtp.host", "smtp.gmail.com");
  16. props.put("mail.smtp.port", "587");
  17.  
  18. System.out.println(props.getProperty("mail.smtp.host"));
  19. Session session = Session.getInstance(props,
  20. new javax.mail.Authenticator() {
  21. protected PasswordAuthentication getPasswordAuthentication() {
  22. return new PasswordAuthentication(username, password);
  23. }
  24. });
  25.  
  26. try {
  27.  
  28. Message message = new MimeMessage(session);
  29. message.setFrom(new InternetAddress("keepitsimplesafe@gmail.com"));
  30. message.setRecipients(Message.RecipientType.TO,
  31. InternetAddress.parse(to));
  32. message.setSubject(subject);
  33. message.setText(content);
  34.  
  35. Transport.send(message);
  36. success="Details Send Successfully";
  37.  
  38. } catch (Exception e) {
  39. throw new RuntimeException(e);
  40. }
  41.  
  42. return success;
  43. }
  44.  
  45. public static void main(String[] args) {
  46. Sendmail send=new Sendmail();
  47. System.out.println(send.sendMail("mypromini2016@gmail.com","hdfh","CHecking MAiling System"));
  48.  
  49.  
  50. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement