List of usage examples for javax.mail Transport send
public static void send(Message msg) throws MessagingException
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); }/*from w w w.j a va 2 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:com.infullmobile.jenkins.plugin.restrictedregister.mail.Mail.java
public void send() throws MailException { MimeMessage msg = null;//from ww w. j a v a 2 s . c o m try { msg = createMessage(); } catch (UnsupportedEncodingException e) { fail("Failed to encode e-mail message, " + e.getLocalizedMessage()); } catch (MessagingException e) { fail(""); } if (msg == null) { throw new NullPointerException("Message must not be null"); } try { Transport.send(msg); } catch (MessagingException e) { fail("Failed to send e-mail message"); } }
From source file:org.xmlactions.email.EMailSend.java
public static void sendEMail(String fromAddress, String toAddress, String host, String userName, String password, String subject, String msg) throws AddressException, MessagingException { log.debug(String.format(//from w ww . j ava2 s . c om "sendEMail(from:%s, to:%s, host:%s, userName:%s, password:%s)\nsubject:{" + subject + "\n}\nmessage:{" + msg + "\n}", fromAddress, toAddress, host, userName, toPassword(password), subject, msg)); Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session; if (!StringUtils.isEmpty(password)) { props.put("mail.smtp.auth", "true"); //EMailAuthenticator auth = new EMailAuthenticator(userName + "+" + host, password); EMailAuthenticator auth = new EMailAuthenticator(userName, password); session = Session.getInstance(props, auth); } else { session = Session.getInstance(props); } // Define message MimeMessage message = new MimeMessage(session); // message.setFrom(new InternetAddress("email_addresses@riostl.com")); message.setFrom(new InternetAddress(fromAddress)); message.addRecipient(RecipientType.TO, new InternetAddress(toAddress)); message.setSubject(subject); message.setText(msg); // Send message if (StringUtils.isEmpty(password)) { Transport.send(message); } else { Provider provider = session.getProvider("smtp"); Transport transport = session.getTransport(provider); // Send message transport.connect(); transport.sendMessage(message, new Address[] { new InternetAddress(toAddress) }); transport.close(); } }
From source file:gov.nih.nci.caintegrator.application.mail.SendMail.java
public synchronized void sendMail(String mailTo, String mailCC, String mailBody, String subject) throws ValidationException { try {/* ww w . j av a 2 s . c o m*/ if (mailTo != null && EmailValidator.getInstance().isValid(mailTo)) { //get system properties Properties props = System.getProperties(); String to = mailTo; // Set up mail server props.put("mail.smtp.host", MailConfig.getInstance(mailProperties).getHost()); //Get session Session session = Session.getDefaultInstance(props, null); //Define Message MimeMessage message = new MimeMessage(session); MailManager mailManager = new MailManager(mailProperties); message.setFrom(new InternetAddress(mailManager.formatFromAddress())); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); if ((mailCC != null) && EmailValidator.getInstance().isValid(mailCC)) message.addRecipient(Message.RecipientType.CC, new InternetAddress(mailCC)); message.setSubject(subject); message.setText(mailBody); //Send Message Transport.send(message); } else { throw new ValidationException("Invalid Email Address"); } } catch (Exception e) { logger.error("Send Mail error", e); } //catch }
From source file:org.nuxeo.ecm.platform.mail.action.SendMailAction.java
public boolean execute(ExecutionContext context) throws MessagingException { Message message = context.getMessage(); if (log.isDebugEnabled()) { log.debug("Sending mail because of message: " + message.getSubject()); }/*from w w w. j av a 2 s . c o m*/ Message sentMessage = new MimeMessage(session); if (message.getReplyTo() == null || message.getReplyTo().length == 0) { return true; } Address address = message.getReplyTo()[0]; sentMessage.setRecipient(Message.RecipientType.TO, address); message.setText(textMessage); Transport.send(sentMessage); return true; }
From source file:com.app.mail.DefaultMailSender.java
@Override public void sendAccountDeletionMessage(String emailAddress) { Session session = _authenticateOutboundEmailAddress(); try {//from ww w . ja v a 2 s . com Message emailMessage = _populateMessage(emailAddress, "Account Deletion Successful", "account_deletion_email.vm", session); Transport.send(emailMessage); } catch (Exception e) { _log.error("Unable to send account deletion message", e); } }
From source file:SendMailImpl.java
public void sendMessage(String from, String[] recipients, String subject, String message) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", smtpHost); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug);//from w w w . j a v a 2 s .c o m // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/html"); Transport.send(msg); }
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 . jav a2 s . co 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:org.nekorp.workflow.desktop.servicio.imp.ServicioAlertaVerificacionEmailImp.java
@Override public void enviarAlerta(List<AlertaVerificacion> alertas) { try {//from w w w . j a v a 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:rapture.mail.Mailer.java
public static void email(CallingContext context, String templateName, Map<String, ? extends Object> templateValues) { final SMTPConfig config = getSMTPConfig(); Session session = getSession(config); EmailTemplate template = getEmailTemplate(context, templateName); try {//from www. j a va 2 s . co m // Instantiate a new MimeMessage and fill it with the required information. Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(config.getFrom())); String to = renderTemplate(template.getEmailTo(), templateValues); if (StringUtils.isBlank(to)) { throw RaptureExceptionFactory.create("No emailTo field"); } InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(renderTemplate(template.getSubject(), templateValues)); msg.setSentDate(new Date()); msg.setContent(renderTemplate(template.getMsgBody(), templateValues), "text/html; charset=utf-8"); // Hand the message to the default transport service for delivery. Transport.send(msg); } catch (MessagingException e) { log.error("Failed to send email", e); } }