List of usage examples for javax.mail.internet InternetAddress parse
public static InternetAddress[] parse(String addresslist) throws AddressException
From source file:org.beangle.notification.notifiers.mail.MimeUtils.java
public static final List<InternetAddress> parseAddress(String address, String encoding) { if (StringUtils.isEmpty(address)) return Collections.emptyList(); try {//from w ww. j av a2s . co m InternetAddress[] parsed = InternetAddress.parse(address); List<InternetAddress> returned = CollectUtils.newArrayList(); for (InternetAddress raw : parsed) { returned.add((encoding != null ? new InternetAddress(raw.getAddress(), raw.getPersonal(), encoding) : raw)); } return returned; } catch (Exception ex) { throw new RuntimeException("Failed to parse embedded personal name to correct encoding", ex); } }
From source file:pl.umk.mat.zawodyweb.email.EmailSender.java
public static void send(String address, String subject, String text) { Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(props); try {//from ww w . j av a2 s . co m Address[] addresses = InternetAddress.parse(address); Message message = new MimeMessage(session); message.setFrom(new InternetAddress(addressFrom)); message.setRecipients(Message.RecipientType.TO, addresses); message.setSubject(subjectPrefix + subject); message.setSentDate(new Date()); message.setText(text); Transport transport = session.getTransport("smtp"); transport.connect(smtpHost, smtpPort, smtpUser, smtpPassword); transport.sendMessage(message, addresses); transport.close(); } catch (MessagingException ex) { log.error(ex); } }
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 ava2 s. c o m }); 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:nz.co.testamation.common.mail.MimeMessageFactoryImpl.java
@Override public Message create(Email email) { try {//from ww w .ja v a2 s. c o m EmailAddresses emailAddresses = email.getEmailAddresses(); MimeMessage mimeMessage = new MimeMessage(session); mimeMessage.setSubject(email.getSubject()); mimeMessage.setFrom(new InternetAddress(emailAddresses.getFrom())); if (StringUtils.isNotBlank(emailAddresses.getReplyTo())) { mimeMessage.setReplyTo(InternetAddress.parse(emailAddresses.getReplyTo())); } addRecipients(mimeMessage, Message.RecipientType.TO, emailAddresses.getToAddresses()); addRecipients(mimeMessage, Message.RecipientType.CC, emailAddresses.getCcAddresses()); addRecipients(mimeMessage, Message.RecipientType.BCC, emailAddresses.getBccAddresses()); mimeMessage.setContent(multipartMessageFactory.create(email)); mimeMessage.setSentDate(new Date()); return mimeMessage; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.nekorp.workflow.desktop.servicio.imp.ServicioAlertaVerificacionEmailImp.java
@Override public void enviarAlerta(List<AlertaVerificacion> alertas) { try {/* w w w . java 2s .c o m*/ for (AlertaVerificacion x : alertas) { Message message = new MimeMessage(template.buildSession()); message.setFrom(new InternetAddress(template.getMailSender())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(template.getMailRecipient())); message.setSubject("Alerta de Verificacin"); ST contenido = new ST(contenidoRaw); contenido.add("placas", x.getPlacas()); contenido.add("periodo", x.getPeriodo()); message.setText(contenido.render()); Transport.send(message); } } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.openhab.binding.mail.internal.MailBuilder.java
/** * Create a new MailBuilder/*from ww w . j av a2 s . co m*/ * * @param recipients comma separated sequence of addresses (must follow RFC822 syntax) * @throws AddressException on invalid recipient address */ public MailBuilder(String recipients) throws AddressException { this.recipients.addAll(Arrays.asList(InternetAddress.parse(recipients))); }
From source file:net.sourceforge.vulcan.mailer.MessageAssembler.java
public MimeMessage constructMessage(String subscribers, ConfigDto config, ProjectStatusDto status, String html) throws MessagingException, AddressException { final MimeMessage message = new MimeMessage(mailSession); message.setSentDate(new Date()); message.setFrom(new InternetAddress(config.getSenderAddress())); if (isNotBlank(config.getReplyToAddress())) { message.setReplyTo(InternetAddress.parse(config.getReplyToAddress())); }/*from w w w . j a v a 2 s . c om*/ message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(subscribers)); message.setSubject(status.getName() + ": " + status.getStatus()); final Multipart multipart = new MimeMultipart(); html = html.replaceAll("\\r", ""); addMultipartBody(multipart, "text/html; charset=UTF-8", html); message.setContent(multipart); return message; }
From source file:util.Support.java
/** * Send email by SSL//from w w w . j a v a 2 s .c om * * @param toEmail Email of user * @param idActive id active authentication */ public static void sendMail(String toEmail, String idActive) { 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"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(util.Constants.FROM_EMAIL, util.Constants.PASSWORD_EMAIL); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(util.Constants.FROM_EMAIL)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail)); message.setSubject("Authentication registration your account."); if (!idActive.isEmpty()) { message.setText("Dear Mail Crawler," + "\n Click to link to complete the registered , please!" + "\n http://localhost:8084/JudiBlog/active?id=" + idActive + ""); } else { message.setText("OK, thank you!" + "\n You have registed successfully!"); } Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.nekorp.workflow.desktop.servicio.imp.ServicioAlertaEmailImp.java
@Override public void enviarAlerta(List<AlertaServicio> alertas) { try {/*from w w w .j a v a2 s. c o m*/ for (AlertaServicio x : alertas) { Message message = new MimeMessage(template.buildSession()); message.setFrom(new InternetAddress(template.getMailSender())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(template.getMailRecipient())); message.setSubject("Alerta"); ST contenido = new ST(contenidoRaw); contenido.add("cliente", x.getNombreCliente()); contenido.add("tipo", x.getTipoAuto()); contenido.add("marca", x.getMarcaAuto()); contenido.add("placas", x.getPlacasAuto()); contenido.add("kilometraje", x.getKilometrajeAuto()); contenido.add("servicio", x.getDescripcionServicio()); contenido.add("kilometrajeServicio", x.getKilometrajeServicio()); message.setText(contenido.render()); Transport.send(message); } } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:Utilities.SendEmailUsingGMailSMTP.java
public void enviarCorreo(String correo, String clave) { String to = correo;/*from w w w. ja v a 2 s . c om*/ final String username = "angelicabarrientosvera@gmail.com";//change accordingly final String password = "90445359D10s";//change accordingly // Assuming you are sending email through relay.jangosmtp.net String host = "smtp.gmail.com"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "587"); props.put("mail.smtp.ssl.trust", "smtp.gmail.com"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { // Create a default MimeMessage object. Message message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(to)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Testing Subject"); // Now set the actual message message.setText("\n" + "Use esta clave para poder restablecer la contrasea" + "\n" + "Tu cdigo para restaurar su cuenta es:" + clave); // Send message Transport.send(message); System.out.println("Sent message successfully...."); //return true; } catch (MessagingException e) { throw new RuntimeException(e); } }