List of usage examples for javax.mail Transport send
public static void send(Message msg) throws MessagingException
From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java
/** * ?/*from w w w.j ava 2 s .co m*/ * @param message * @throws EnterpriseException ? */ private static void send(final Message message) throws EnterpriseException { try { Transport.send(message); } catch (final MessagingException e) { throw new EnterpriseException(e.getLocalizedMessage()); } }
From source file:uk.ac.ox.it.ords.api.statistics.services.impl.SendMailTLS.java
private void sendMail() { if (sendEmails) { if (username == null) { log.error("Unable to send emails due to null user"); return; }/*from w w w .j a v a2 s . c om*/ Session session = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(props.get("mail.smtp.username").toString(), props.get("mail.smtp.password").toString()); } }); try { Message message = new MimeMessage(session); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject(subject); message.setText(messageText); message.setFrom(new InternetAddress("ords@it.ox.ac.uk")); Transport.send(message); if (log.isDebugEnabled()) { log.debug(String.format("Sent email to %s (name %s)", email, username)); log.debug("with content: " + messageText); } } catch (MessagingException e) { log.error("Unable to send email to " + email + " username " + username, e); } } }
From source file:jease.cms.service.Mails.java
/** * Sends an email synchronously.//w ww . j ava2 s . com */ public void send(String sender, String recipients, String subject, String text) throws MessagingException { if (properties != null) { Session session = Session.getInstance(properties.asProperties(), new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(properties.getUser(), properties.getPassword()); } }); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(sender)); message.setReplyTo(new InternetAddress[] { new InternetAddress(sender) }); message.setRecipients(Message.RecipientType.TO, recipients); message.setSubject(subject, "utf-8"); message.setSentDate(new Date()); message.setHeader("Content-Type", "text/plain; charset=\"utf-8\""); message.setHeader("Content-Transfer-Encoding", "quoted-printable"); message.setText(text, "utf-8"); Transport.send(message); } }
From source file:com.gitlab.anlar.lunatic.server.ServerTest.java
private void sendSinglePartEmail(String from, String to, String subject, String body) throws MessagingException { Properties props = createEmailProps(serverPort); Session session = Session.getInstance(props); Message msg = createBaseMessage(from, to, subject, session); msg.setText(body);// w ww .ja v a 2 s.c om Transport.send(msg); }
From source file:com.anteam.alert.email.service.EmailAntlert.java
@Override public boolean send(AntlertMessage antlertMsg) { MimeMessage mimeMsg; // MIME // from?to?/*w ww . j a va 2 s . c om*/ mimeMsg = new javax.mail.internet.MimeMessage(mailSession); try { // ? mimeMsg.setFrom(sender); // mimeMsg.setRecipients(RecipientType.TO, receivers); // mimeMsg.setSubject(antlertMsg.getTitle(), CHARSET); // MimeBodyPart messageBody = new MimeBodyPart(); messageBody.setContent(antlertMsg.getContent(), CONTENT_MIME_TYPE); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBody); mimeMsg.setContent(multipart); // ?? mimeMsg.setSentDate(new Date()); mimeMsg.saveChanges(); // ?? Transport.send(mimeMsg); } catch (MessagingException e) { logger.error("???", e); return false; } return true; }
From source file:de.tuttas.servlets.MailSender.java
private void transmitMail(MailObject mo) throws MessagingException { // creates a new session with an authenticator Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(Config.getInstance().user, Config.getInstance().pass); }//from w w w .j a v a 2 s . c om }; Session session = Session.getInstance(properties, auth); // creates a new e-mail message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(mo.getFrom())); InternetAddress[] toAddresses = mo.getRecipient(); msg.setRecipients(Message.RecipientType.TO, toAddresses); InternetAddress[] bccAdresses = mo.getBcc(); InternetAddress[] ccAdresses = mo.getCC(); if (bccAdresses[0] != null) msg.setRecipients(Message.RecipientType.BCC, bccAdresses); if (ccAdresses[0] != null) msg.setRecipients(Message.RecipientType.CC, ccAdresses); msg.setSubject(mo.getSubject(), "UTF-8"); msg.setSentDate(new Date()); msg.setContent(mo.getContent(), "text/plain; charset=UTF-8"); // sends the e-mail // TODO Kommentar entfernen Transport.send(msg); }
From source file:com.krawler.notify.email.SimpleEmailSender.java
public synchronized void send(Message msg) throws NotificationException { try {/* w w w. jav a 2s . co m*/ logger.info(defaults); Transport.send(msg); } catch (Exception e) { throw new NotificationException(captureMessage(e), e); } finally { loadSize--; } }
From source file:com.bizintelapps.cars.service.impl.EmailServiceImpl.java
/** * /*w w w . j av a 2 s . co m*/ * @param recipients * @param subject * @param message * @param from * @throws MessagingException */ private void sendSSMessage(String recipients[], String subject, Car car, String comment) { try { InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { if (recipients[i] != null && recipients[i].length() > 0) { addressTo[i] = new InternetAddress(recipients[i]); } } if (addressTo == null || addressTo.length == 0) { return; } boolean debug = true; Properties props = new Properties(); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); props.put("mail.smtp.port", SMTP_PORT); props.put("mail.smtp.socketFactory.port", SMTP_PORT); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); props.put("mail.smtp.socketFactory.fallback", "false"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(SEND_FROM_USERNAME, SEND_FROM_PASSWORD); } }); session.setDebug(debug); Message msg = new MimeMessage(session); InternetAddress addressFrom = new InternetAddress(EMAIL_FROM_ADDRESS); msg.setFrom(addressFrom); msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); String message = buildMessage(car, comment); msg.setContent(message, EMAIL_CONTENT_TYPE); Transport.send(msg); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); throw new RuntimeException("Error sending email, please check to and from emails are correct!"); } }
From source file:org.infoglue.common.util.mail.MailService.java
/** * * @param from the sender of the email.// ww w . ja v a 2s .c o m * @param to the recipient of the email. * @param subject the subject of the email. * @param content the body of the email. * @throws SystemException if the email couldn't be sent due to some mail server exception. */ public void send(String from, String to, String bcc, String subject, String content, String contentType, String encoding, List attachments) throws SystemException { final Message message = createMessage(from, to, bcc, subject, content, contentType, encoding, attachments); try { Transport.send(message); log.info("Mail sent..."); } catch (MessagingException e) { log.error("Unable to send message: " + e.getMessage(), e); //e.printStackTrace(); throw new SystemException("Unable to send message.", e); } }
From source file:org.lf.yydp.service.film.BuyTicketService.java
/** * :?/* ww w . j av a 2 s. c o m*/ * @param receiver */ public void sendEmail(String receiver) { Properties p = null; InputStream inputSteam = null; String senter = null; String Subject = null; String Content = null; try { p = new Properties(); inputSteam = BuyTicketService.class.getClassLoader().getResourceAsStream("mail.properties"); p.load(inputSteam); final String uname = p.getProperty("mail.uname"); final String license = p.getProperty("mail.license"); senter = p.getProperty("mail.senter"); Subject = p.getProperty("mail.subject"); Content = p.getProperty("mail.content"); Authenticator authenticator = new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(uname, license); } }; Session session = Session.getInstance(p, authenticator); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(senter)); msg.setRecipient(RecipientType.TO, new InternetAddress(receiver)); msg.setSubject(Subject); msg.setContent(Content, "text/html;charset=utf-8"); Transport.send(msg); } catch (Exception e) { e.printStackTrace(); } finally { try { if (inputSteam != null) { inputSteam.close(); } } catch (Exception e2) { e2.printStackTrace(); } } }