Example usage for javax.mail.internet InternetAddress InternetAddress

List of usage examples for javax.mail.internet InternetAddress InternetAddress

Introduction

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

Prototype

public InternetAddress(String address) throws AddressException 

Source Link

Document

Constructor.

Usage

From source file:com.local.ask.controller.mail.MailManagerImpl.java

@Override
public void confirmRegistration(UserTemp userTemp) {

    try {/*from  www  .  j a va2s . c  o  m*/

        MimeMessage message = mailSender.createMimeMessage();

        message.setSubject("Local Ask - Confirm Registration");
        message.setFrom(new InternetAddress("local.ask.com@gmail.com"));

        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setTo(userTemp.getEmail());
        String text;
        text = template.replace("{displayName}", userTemp.getDisplayName())
                .replace("{email}", userTemp.getEmail()).replace("{id}", userTemp.getConfirmCode());

        helper.setText(text, true);

        mailSender.send(message);

    } catch (MessagingException ex) {
        Logger.getLogger(MailManagerImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.bitranger.parknshop.mail.EMailSender.java

public boolean send(String address, String subject, String content) {

    LOG.debug("sending message [" + subject + "] to [" + address + "]");

    MimeMessage msg = sender.createMimeMessage();

    try {//from   w w w.  ja  v a  2s  . c o m
        msg.setRecipient(RecipientType.TO, new InternetAddress(address));
        msg.setSubject(subject);
        msg.setText(content);

        sender.send(msg);

    } catch (Exception e) {
        LOG.error("failed sending email to [" + address + "]" + " subject [" + subject + "] content[" + content
                + "]");
        return false;
    }
    return false;
}

From source file:com.clueride.domain.account.principal.EmailPrincipal.java

public EmailPrincipal(String email) {
    try {/*from   ww  w.j  av  a 2  s.c om*/
        emailAddress = new InternetAddress(email);
    } catch (AddressException e) {
        e.printStackTrace();
    }
}

From source file:com.mycompany.apps.MailService.java

public void doSomeService() {
    HashMap map = new HashMap();
    map.put("name", "hoge");
    map.put("today", "2014/11/20");
    // ... ?map?????
    String msg = mailBuilder.buildMessage(map);
    System.out.println("?:" + msg);

    try {// w  w  w  .ja v a  2 s .co  m
        SimpleEmail email = new SimpleEmail();
        //??
        email.setHostName("localhost");
        //??
        List to = new ArrayList();
        InternetAddress to1 = new InternetAddress("to1@mail.myserver.com");
        to.add(to1);
        InternetAddress to2 = new InternetAddress("to2@mail.myserver.com");
        to.add(to2);
        email.setTo(to);

        //??
        email.setFrom("from@mail.myserver.com");
        //?
        email.addReplyTo("reply@mail.myserver.com");
        //??
        email.setSubject("");
        //??
        email.setMsg(msg);
        //??
        //            email.send();
    } catch (EmailException ex) {
        ex.printStackTrace();
    } catch (AddressException ex) {
        ex.printStackTrace();
    }
}

From source file:com.email.SendEmailCrashReport.java

/**
 * Sends crash email to predetermined list from the database.
 *
 * Also BCCs members of XLN team for notification of errors
 *///from   w  w w .  jav a  2 s .  c o  m
public static void sendCrashEmail() {
    //Get Account
    SystemEmailModel account = null;
    for (SystemEmailModel acc : Global.getSystemEmailParams()) {
        if (acc.getSection().equals("ERROR")) {
            account = acc;
            break;
        }
    }

    if (account != null) {
        String FROMaddress = account.getEmailAddress();
        List<String> TOAddresses = SystemErrorEmailList.getActiveEmailAddresses();
        String[] BCCAddressess = ("Anthony.Perk@XLNSystems.com".split(";"));
        String subject = "SERB 3.0 Application Daily Error Report for "
                + Global.getMmddyyyy().format(Calendar.getInstance().getTime());
        String body = buildBody();

        Authenticator auth = EmailAuthenticator.setEmailAuthenticator(account);
        Properties properties = EmailProperties.setEmailOutProperties(account);

        Session session = Session.getInstance(properties, auth);
        MimeMessage email = new MimeMessage(session);

        try {
            for (String TO : TOAddresses) {
                if (EmailValidator.getInstance().isValid(TO)) {
                    email.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
                }
            }

            for (String BCC : BCCAddressess) {
                if (EmailValidator.getInstance().isValid(BCC)) {
                    email.addRecipient(Message.RecipientType.BCC, new InternetAddress(BCC));
                }
            }

            email.setFrom(new InternetAddress(FROMaddress));
            email.setSubject(subject);
            email.setText(body);
            Transport.send(email);
        } catch (AddressException ex) {
            ExceptionHandler.Handle(ex);
        } catch (MessagingException ex) {
            ExceptionHandler.Handle(ex);
        }
    } else {
        System.out.println("No account found to send Error Email");
    }
}

From source file:com.mimp.hibernate.HiberMail.java

public static void generateAndSendEmail(String correo, String pass_plano, String user) {

    final String username = "formacionadopcion@gmail.com";
    final String password = "cairani.";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }/* w w  w  .  j a v a  2 s .  c om*/
    });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("formacionadopcion@gmail.com"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(correo));
        message.setSubject("Sistema de adopciones");
        message.setText("Estimado solicitante,"
                + "\n\n Su solicitud de recuperacin de contrasea ha sido procesada. Su usuario y contrasea para acceder a la plataforma de adopciones son los siguientes:"
                + "\n\n Usuario: " + user + "\n\n Contrasea: " + pass_plano + "\n\n Saludos cordiales, ");

        Transport.send(message);

    } catch (Exception ex) {

    }

    /*catch (MessagingException e) {
     throw new RuntimeException(e);
     }*/
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.MailUtil.java

public void sendMessage(String messageText, String subject, String from, String to, List<String> deliverToArray)
        throws IOException {

    Session s = FreemarkerEmailFactory.getEmailSession(req);

    try {//from  w  w  w .j a va  2s.c o  m

        int recipientCount = (deliverToArray == null) ? 0 : deliverToArray.size();
        if (recipientCount == 0) {
            log.error("To establish the Contact Us mail capability the system administrators must  "
                    + "specify at least one email address in the current portal.");
        }

        MimeMessage msg = new MimeMessage(s);
        // Set the from address
        msg.setFrom(new InternetAddress(from));

        // Set the recipient address

        if (recipientCount > 0) {
            InternetAddress[] address = new InternetAddress[recipientCount];
            for (int i = 0; i < recipientCount; i++) {
                address[i] = new InternetAddress(deliverToArray.get(i));
            }
            msg.setRecipients(Message.RecipientType.TO, address);
        }

        // Set the subject and text
        msg.setSubject(subject);

        // add the multipart to the message
        msg.setContent(messageText, "text/html");

        // set the Date: header
        msg.setSentDate(new Date());
        Transport.send(msg); // try to send the message via smtp - catch error exceptions
    } catch (Exception ex) {
        log.error("Exception sending message :" + ex.getMessage(), ex);
    }
}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void sendGRUP(String from, String password, String bcc, String sub, String msg, String filename)
        throws Exception {
    //Get properties object    
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    //get Session   
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(from, password);
        }//from  w ww.ja  v a 2  s.co  m
    });
    //compose message    
    try {
        MimeMessage message = new MimeMessage(session);
        //message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));

        message.setSubject(sub);
        message.setText(msg);

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Raport teste automat");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        //message.setContent(multipart);
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        message.setContent(writer.toString(), "text/html");

        //send message  
        Transport.send(message);
        System.out.println("message sent successfully");
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.arsdigita.util.parameter.EmailParameter.java

protected Object unmarshal(final String value, final ErrorList errors) {
    try {// w w  w .j a  va 2s .c om
        return new InternetAddress(value);
    } catch (AddressException ae) {
        errors.add(new ParameterError(this, ae));
        return null;
    }
}

From source file:easyproject.service.Mail.java

public void sendMail() {
    Properties props = new Properties();

    props.put("mail.debug", "true");
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.starttls.enable", true);
    props.put("mail.smtp.host", servidorSMTP);
    props.put("mail.smtp.port", puerto);

    Session session = Session.getInstance(props, null);

    try {//  ww w.  j a v a  2 s.  co m
        MimeMessage message = new MimeMessage(session);

        message.addRecipient(Message.RecipientType.TO, new InternetAddress(destino));
        message.setSubject(asunto);
        message.setSentDate(new Date());
        message.setContent(mensaje, "text/html; charset=utf-8");

        Transport tr = session.getTransport("smtp");
        tr.connect(servidorSMTP, usuario, password);
        message.saveChanges();
        tr.sendMessage(message, message.getAllRecipients());
        tr.close();

    } catch (MessagingException e) {
        e.printStackTrace();
    }
}