Guest User

Untitled

a guest
Feb 7th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package enviar.correo;
  2. import java.util.Properties;
  3. import javax.mail.Message;
  4. import javax.mail.MessagingException;
  5. import javax.mail.Session;
  6. import javax.mail.Transport;
  7. import javax.mail.internet.InternetAddress;
  8. import javax.mail.internet.MimeMessage;
  9. /**
  10.  *
  11.  * @author gerso_000
  12.  */
  13. public class enviar {
  14.    
  15.     private final Properties properties = new Properties();
  16.    
  17.     private String password="Bleach2015";
  18.  
  19.     private Session session;
  20.  
  21.     public void init() {
  22.  
  23.         properties.put("mail.smtp.host", "mail.gmail.com");
  24.         properties.put("mail.smtp.starttls.enable", "true");
  25.         properties.put("mail.smtp.port",25);
  26.         properties.put("mail.smtp.mail.sender","gersoncaballero306@gmail.com");
  27.         properties.put("mail.smtp.user", "gersoncaballero306@gmail.com");
  28.         properties.put("mail.smtp.auth", "true");
  29.  
  30.         session = Session.getDefaultInstance(properties);
  31.     }
  32.  
  33.     public void sendEmail(){
  34.  
  35.         init();
  36.         try{
  37.             MimeMessage message = new MimeMessage(session);
  38.             message.setFrom(new InternetAddress((String)properties.get("mail.smtp.mail.sender")));
  39.             message.addRecipient(Message.RecipientType.TO, new InternetAddress("gersoncaballero306@gmail.com"));
  40.             message.setSubject("Prueba");
  41.             message.setText("que tal computek le manda un cordeal saludo espero este super bien");
  42.             Transport t = session.getTransport("smtp");
  43.             t.connect((String)properties.get("mail.smtp.user"), "password");
  44.             t.sendMessage(message, message.getAllRecipients());
  45.                         System.out.println("El mensaje fue enviado");    
  46.             t.close();
  47.         }catch (MessagingException me){
  48.                 System.out.println("El mensaje no fue enviado");    
  49.         return;
  50.         }
  51.        
  52.     }
  53.    
  54.    
  55. }
Add Comment
Please, Sign In to add comment