Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Properties props = new Properties();
- props.put("mail.smtp.host" , "smtp.gmail.com");
- props.put("mail.stmp.user" , "horiond@gmail.com");
- //TLS
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.password", "xxxxx");
- //SSL
- props.put("mail.smtp.socketFactory.port", "465");
- props.put("mail.smtp.socketFactory.class",
- "javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.port", "465");
- Session session = Session.getDefaultInstance( props , null);
- String to = "horiond@gmail.com";
- String from = "horiond@gmail.com";
- String subject = "Testing...";
- Message msg = new MimeMessage(session);
- try {
- msg.setFrom(new InternetAddress(from));
- msg.setRecipient(Message.RecipientType.TO,
- new InternetAddress(to));
- msg.setSubject(subject);
- msg.setText("Working fine..!");
- Transport transport = session.getTransport("smtp");
- transport.connect("smtp.gmail.com" , 465 , "horiondev@gmail.com", "messages3881");
- transport.send(msg);
- System.out.println("fine!!");
- }
- catch(Exception exc) {
- System.out.println(exc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement