My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.lineadecodigo.java.mail;

/**
* @file MandarEmail.java
* @version 1.0
* @author Linea de Codigo (http://lineadecodigo.com)
* @date 26.marzo.2011
* @url http://lineadecodigo.com/java/mandar-emails-con-javamail/
* @description Clase que nos permite enviar un email con Java Mail
*/

import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;

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();
}

}
}

Change log

r348 by vcuervo on Mar 25, 2011   Diff
Enviar email con Java Mail
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1476 bytes, 50 lines
Powered by Google Project Hosting