Example usage for javax.mail.internet MimeMessage setText

List of usage examples for javax.mail.internet MimeMessage setText

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage setText.

Prototype

@Override
public void setText(String text) throws MessagingException 

Source Link

Document

Convenience method that sets the given String as this part's content, with a MIME type of "text/plain".

Usage

From source file:org.apache.axis2.transport.mail.MailClient.java

public void sendMessage(String to, String subject, String content, String soapAction)
        throws MessagingException {
    log.info("SENDING message from " + from + " to " + to);

    MimeMessage msg = new MimeMessage(session);

    msg.setHeader("transport.mail.soapaction", soapAction);
    msg.addRecipients(Message.RecipientType.TO, to);
    msg.setSubject(subject);/*  w ww .  j av  a 2 s  .c om*/
    msg.setText(content);
    Transport.send(msg);
}

From source file:org.ktunaxa.referral.server.command.test.TestEmailCommand.java

@Override
public void execute(TestEmailRequest request, TestEmailResponse response) throws Exception {
    final String from = "rms@ktunaxa.org";
    final String to = request.getTo();
    if (null == to) {
        throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "to");
    }//from www.  j a va  2 s  . c  om
    MimeMessagePreparator preparator = new MimeMessagePreparator() {

        public void prepare(MimeMessage mimeMessage) throws Exception {

            mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            mimeMessage.setFrom(new InternetAddress(from));
            mimeMessage.setSubject("Test");
            mimeMessage.setText("Testing RMS");
        }
    };
    mailSender.send(preparator);
}

From source file:org.mobicents.servlet.restcomm.email.EmailService.java

EmailResponse send(final Mail mail) {
    try {/*from   w ww  . j a va 2 s . c om*/
        InternetAddress from;
        if (mail.from() != null || !mail.from().equalsIgnoreCase("")) {
            from = new InternetAddress(mail.from());
        } else {
            from = new InternetAddress(user);
        }
        final InternetAddress to = new InternetAddress(mail.to());
        final MimeMessage email = new MimeMessage(session);
        email.setFrom(from);
        email.addRecipient(Message.RecipientType.TO, to);
        email.setSubject(mail.subject());
        email.setText(mail.body());
        email.addRecipients(Message.RecipientType.CC, InternetAddress.parse(mail.cc(), false));
        email.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(mail.bcc(), false));
        Transport.send(email);
        return new EmailResponse(mail);
    } catch (final MessagingException exception) {
        logger.error(exception.getMessage(), exception);
        return new EmailResponse(exception, exception.getMessage());
    }
}

From source file:org.openiam.idm.srvc.msg.service.MailSender.java

public void send(Message msg) {
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(properties);
    MimeMessage message = new MimeMessage(session);
    try {//from  w  w w .j  av  a2 s  .c  o  m
        message.setFrom(msg.getFrom());
        message.addRecipient(javax.mail.Message.RecipientType.TO, msg.getTo());
        message.setSubject(msg.getSubject());
        message.setText(msg.getBody());

        Transport.send(message);
        log.info("Message successfully sent.");
    } catch (MessagingException me) {
        log.error(me);
        me.printStackTrace();
    }
}

From source file:cl.preguntame.controller.PlataformaController.java

@ResponseBody
@RequestMapping(value = "/email", method = RequestMethod.POST)
public String correo(HttpServletRequest req) {

    try {//from  ww w. java  2s  . c o  m
        String host = "smtp.gmail.com";

        Properties prop = System.getProperties();

        prop.put("mail.smtp.starttls.enable", "true");
        prop.put("mail.smtp.host", host);
        prop.put("mail.smtp.user", "hector.riquelme1169@gmail.com");
        prop.put("mail.smtp.password", "rriiqquueellmmee");
        prop.put("mail.smtp.port", 587);
        prop.put("mail.smtp.auth", "true");

        Session sesion = Session.getDefaultInstance(prop, null);
        MimeMessage mensaje = new MimeMessage(sesion);

        mensaje.setFrom(new InternetAddress());
        mensaje.setRecipient(Message.RecipientType.TO, new InternetAddress("hector.riquelme1169@gmail.com"));
        mensaje.setSubject("CONTACTO MIS CONCEPTOS");
        mensaje.setText(req.getParameter("mensaje_contacto"));

        Transport transport = sesion.getTransport("smtp");
        transport.connect(host, "hector.riquelme1169@gmail.com", "rriiqquueellmmee");
        transport.sendMessage(mensaje, mensaje.getAllRecipients());

        transport.close();

    } catch (Exception e) {

    }

    return req.getParameter("mensaje_contacto") + "  -  " + req.getParameter("email_contacto");
}

From source file:com.jive.myco.seyren.core.service.notification.EmailNotificationService.java

private MimeMessage createMimeMessage(Email email) throws AddressException, MessagingException {

    MimeMessage mail = mailSender.createMimeMessage();
    InternetAddress senderAddress = new InternetAddress(email.getFrom());
    mail.addRecipient(RecipientType.TO, new InternetAddress(email.getTo()));
    mail.setSender(senderAddress);/*from w  ww  .j a v  a 2 s. c o m*/
    mail.setFrom(senderAddress);
    mail.setText(email.getMessage());
    mail.setSubject(email.getSubject());
    mail.addHeader("Content-Type", "text/html; charset=UTF-8");

    return mail;
}

From source file:com.unilever.audit.services2.ForgetPassword.java

@GET
@Path("Email/{email}")
@Produces("application/json")
public String LoginIn(@PathParam("email") String email) throws IOException {
    boolean status = true;
    String error = null;//from  w ww  .  j av a  2  s .co m
    JSONObject result = new JSONObject();

    Map<String, Object> hm = new HashMap<String, Object>();
    hm.put("email", email);
    Merchandisers merchidisers = (Merchandisers) merchandisersFacadeREST
            .findOneByQuery("Merchandisers.findByEmail", hm);
    if (merchidisers == null) {
        status = false;
        error = "invalid email";
    } else {
        Properties props = new Properties();
        final String from = "";
        final String password = "";
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.user", from);
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.password", password);
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.auth", "true");

        Session session = Session.getInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, password);
            }
        });
        session.setDebug(true);
        try {
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom();
            msg.setRecipients(Message.RecipientType.TO, email);
            msg.setSubject("Unilever Confirmation");
            msg.setSentDate(new Date());
            msg.setText("");
            Transport.send(msg);
        } catch (MessagingException ex) {
            //  status = false;
            //  error="Error Sending Email";
            ex.printStackTrace();
        }
    }
    result.put("status", status);
    result.put("error", error);
    System.out.println("----------------" + result.toString());
    return result.toString();
}

From source file:org.restcomm.connect.email.EmailService.java

EmailResponse sendEmailSsL(final Mail mail) {
    try {/*from   w w  w.j a  va  2  s . com*/
        InternetAddress from;
        if (mail.from() != null || !mail.from().equalsIgnoreCase("")) {
            from = new InternetAddress(mail.from());
        } else {
            from = new InternetAddress(user);
        }
        final InternetAddress to = new InternetAddress(mail.to());
        final MimeMessage email = new MimeMessage(session);
        email.setFrom(from);
        email.addRecipient(Message.RecipientType.TO, to);
        email.setSubject(mail.subject());
        email.setText(mail.body());
        email.addRecipients(Message.RecipientType.CC, InternetAddress.parse(mail.cc(), false));
        email.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(mail.bcc(), false));
        //Transport.send(email);
        transport.connect(host, Integer.parseInt(port), user, password);
        transport.sendMessage(email, email.getRecipients(Message.RecipientType.TO));
        return new EmailResponse(mail);
    } catch (final MessagingException exception) {
        logger.error(exception.getMessage(), exception);
        return new EmailResponse(exception, exception.getMessage());
    }
}

From source file:org.quartz.jobs.ee.mail.SendMailJob.java

protected void setMimeMessageContent(MimeMessage mimeMessage, MailInfo mailInfo) throws MessagingException {
    if (mailInfo.getContentType() == null) {
        mimeMessage.setText(mailInfo.getMessage());
    } else {//from  w w w  . j av  a  2  s. c  o m
        mimeMessage.setContent(mailInfo.getMessage(), mailInfo.getContentType());
    }
}

From source file:org.tomitribe.tribestream.registryng.service.monitoring.MailAlerter.java

private void sendMail(final Alert alert) throws MessagingException {
    final String subject = StrSubstitutor.replace(subjectTemplate, new HashMap<String, String>() {
        {//from   w ww.j a v  a2s  .  c  o  m
            put("hostname", hostname);
            put("date", LocalDateTime.now().toString());
        }
    });
    final String body = alert.text();

    final MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(body);
    Transport.send(message);
}