Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package enviar.correo;
- import java.util.Properties;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- /**
- *
- * @author gerso_000
- */
- public class enviar {
- private final Properties properties = new Properties();
- private String password="Bleach2015";
- private Session session;
- public void init() {
- properties.put("mail.smtp.host", "mail.gmail.com");
- properties.put("mail.smtp.starttls.enable", "true");
- properties.put("mail.smtp.port",25);
- properties.put("mail.smtp.mail.sender","gersoncaballero306@gmail.com");
- properties.put("mail.smtp.user", "gersoncaballero306@gmail.com");
- properties.put("mail.smtp.auth", "true");
- session = Session.getDefaultInstance(properties);
- }
- public void sendEmail(){
- init();
- try{
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress((String)properties.get("mail.smtp.mail.sender")));
- message.addRecipient(Message.RecipientType.TO, new InternetAddress("gersoncaballero306@gmail.com"));
- message.setSubject("Prueba");
- message.setText("que tal computek le manda un cordeal saludo espero este super bien");
- Transport t = session.getTransport("smtp");
- t.connect((String)properties.get("mail.smtp.user"), "password");
- t.sendMessage(message, message.getAllRecipients());
- System.out.println("El mensaje fue enviado");
- t.close();
- }catch (MessagingException me){
- System.out.println("El mensaje no fue enviado");
- return;
- }
- }
- }
Add Comment
Please, Sign In to add comment