Java:Session
De W3API
Contenido |
[editar] Descripcion
Representa una sesión de mail.
[editar] Sintaxis
public final class Session extends Object
[editar] Ejemplo
public class MandarEmail {
public static void main(java.lang.String[] args) {
try {
// Configuramos las propiedades
Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host","mail.lineadecodigo.com");
// Creo la sesión y un nuevo mensaje de correo
Autentificacion pwd = new Autentificacion();
Session mailSession = Session.getInstance(props,pwd);
Message msg = new MimeMessage(mailSession);
// Configuramos los campos del mensaje
msg.setFrom(new InternetAddress("yo@lineadecodigo.com"));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("destinatario@email.com"));
msg.setSubject("Tema del mensaje");
String msgBody = "Cuerpo del mensaje";
DataHandler dh = new DataHandler(msgBody,"text/plain");
msg.setDataHandler(dh);
// Pedimos a la clase Transport que envie el mensaje de correo
javax.mail.Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
[editar] Campos
[editar] Constuctores
- No tiene
[editar] Metodos
- addProvider()
- getDebug()
- getDebugOut()
- getDefaultInstance()
- getFolder()
- getInstance()
- getPasswordAuthentication()
- getProperties()
- getProperty()
- getProvider()
- getProviders()
- getStore()
- getTransport()
- requestPasswordAuthentication()
- setDebug()
- setDebugOut()
- setPasswordAuthentication()
- setProtocolForAddress()
- setProvider()