Tema: JamavaMail
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/04/2012, 02:12
Malkav14n
 
Fecha de Ingreso: abril-2012
Ubicación: Madrid
Mensajes: 28
Antigüedad: 12 años, 1 mes
Puntos: 3
Información Respuesta: JamavaMail

Completando mi respuesta de ayer, y aprovechando que hoy estoy en mi equipo de "spam", te mando mi clase "Send":

Código:
/** datos lleva nombre y mail de cada destinatario, out = log que dejamos de los envíos 
*/
public static void send(DatosDireccion datos, BufferedWriter out) throws IOException {
   
	    try {
	
	    	Properties props = new Properties();
	    	props.put("mail.smtp.host", "/*servidor de correo*/");
	    	props.put("mail.smtp.auth", "true");
	    	props.put("mail.debug", "false");
	
	    	Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
	    		protected PasswordAuthentication getPasswordAuthentication() {
	    			return new PasswordAuthentication("/*usuario*/", "/*password*/");
	    		}
	    	});
	
	    	Message msg = new MimeMessage(session);
	    	msg.setFrom(
	    			new InternetAddress("/*mail remitente*/", "/*nombre remitente*/ "));
	    			
	    	try {
	    		msg.setRecipient(Message.RecipientType.TO, getAddress(datos.getMail()));
	    	} catch (UnsupportedEncodingException uee) {
	    		System.err.println("Recipient KO");
	    		uee.printStackTrace();	    		
	    	}
	    	
	    	msg.setSubject("/*asunto*/");
	    	
	    	BodyPart messageBodyPart = new MimeBodyPart();
	    	messageBodyPart.setContent("/*yo le paso el mensaje en html*/", "text/html");
	    	msg.setContent(multipart);
	    	
	    	// Prioridad al envío
	    	// 1 La más alta - 3 Normal - 5 la más baja
	    	msg.addHeader("X-Priority", "3");
	
	    	// Enviamos el mensaje
	    	Transport.send(msg);
	
	    	/*log*/
	    } catch (Exception ex) {
	    	/*log error*/
	    }
	}

Espero que te pueda orientar o servir de ayuda.