Package fr.isis.cloud

Source Code of fr.isis.cloud.Mail

package fr.isis.cloud;

import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class Mail extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {

    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    String objet = req.getParameter("objet");
    String message = req.getParameter("message");
    String addrUsr = req.getParameter("addrusr");

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("julien.plagnes@gmail.com",
          "Julien & Co"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          addrUsr, "User"));
      msg.setSubject(objet);
      msg.setText(message);
      Transport.send(msg);

      resp.sendRedirect("/");
    } catch (AddressException e) {
      // ...
    } catch (MessagingException e) {
      // ...
    }
  }
}
TOP

Related Classes of fr.isis.cloud.Mail

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.