Package voxo.server.services

Source Code of voxo.server.services.MailService

package voxo.server.services;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import voxo.server.Messages;

public class MailService {
  private static String  _serveurSMTP  = Messages.getString("MailService.CFG_SMTP_Server"); //$NON-NLS-1$
  private static String  _typeContenu  = Messages.getString("MailService.CFG_MailContentType"); //$NON-NLS-1$

  public static void sendMail(String source, String sourceName, String destination, String destinationName, String subject, String body) throws UnsupportedEncodingException, MessagingException {
    Properties properties = System.getProperties();
    properties.put("mail.smtp.host", _serveurSMTP); //$NON-NLS-1$
    Session session = Session.getDefaultInstance(properties, null);

    // Construire le message
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(source, sourceName));

    message.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress(destination, destinationName));
    message.setSubject(subject);
    message.setText(body);
    message.setHeader("Content-Type", _typeContenu); //$NON-NLS-1$
    message.setSentDate(new Date());

    // Envoi du courrier
    Transport.send(message);
  }
}
TOP

Related Classes of voxo.server.services.MailService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.