Bueno algo muy sencillo por si necesitan enviar correos a traves de java.
Para ello adicionamos las librerias necesarias:
mail.jar //La conseguimos en la siguiente direccion:
http://www.oracle.com/technetwork/java/index-138643.html
y la otra es:
jaf.jar
http://www.oracle.com/technetwork/java/jaf102-139581.html
Listo ahora agregamos los jar a nuestras librerías.
una vez hecho eso creamos un package llamado mail y creamos una clase con el nombre de Enviar correo.
luego agregamos el código a continuación y lo llamamos pasando los parámetros que nos pide..
A por cierto en el smtpHost podemos poner la ip de nuestro servidor de correo o su nombre....
Es muy sencillo!!! espero que les ayude..
/** * * @author icano */ import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class EnviarCorreo { public int EnviarCorreo (String remitente, String asunto, String destinatario,String cuerpo) { int status = 1; String from = remitente; String to = destinatario; // Se obtienen las propiedades del sistema y se establece el servidor SMTP String smtpHost = "10.xx.xx.xx"; //Direccion de nuestro servidor Tambien se puede poner correo.empresa.com Properties props = System.getProperties(); props.put("mail.smtp.host",smtpHost); // Se obtiene una sesión con las propiedades anteriormente definidas Session sesion = Session.getDefaultInstance(props,null); // Capturar las excepciones try { // Se crea un mensaje vacío Message mensaje = new MimeMessage(sesion); // Se rellenan los atributos y el contenido // Asunto mensaje.setSubject(asunto); // Emisor del mensaje mensaje.setFrom(new InternetAddress(from)); // Receptor del mensaje mensaje.addRecipient( Message.RecipientType.TO,new InternetAddress(to)); // Cuerpo del mensaje mensaje.setText(cuerpo); // Se envía el mensaje Transport.send(mensaje); } catch (MessagingException e) { System.err.println(e.getMessage()); status = 0; } return status; } }
1 comentario:
Casino Finder (Google Play) Reviews & Demos - Go
Check https://tricktactoe.com/ Casino Finder (Google Play). A look gri-go.com at casino-roll.com some of the best gambling sites in the sol.edu.kg world. They https://vannienailor4166blog.blogspot.com/ offer a full game library,
Publicar un comentario