List of usage examples for javax.mail.internet MimeMessage setFrom
public void setFrom(String address) throws MessagingException
From source file:ru.org.linux.util.EmailService.java
public void sendEmail(String nick, String email, boolean isNew) throws MessagingException { StringBuilder text = new StringBuilder(); text.append("?!\n\n"); if (isNew) {// w w w . j a va 2 s . c o m text.append( "\t? ? http://www.linux.org.ru/ ?? ?? ?,\n"); } else { text.append( "\t? ? http://www.linux.org.ru/ ?? ?,\n"); } text.append(" ? ? (e-mail).\n\n"); text.append( " ? ? ? ?: '"); text.append(nick); text.append("'\n\n"); text.append( "? , - ? ? ?!\n\n"); if (isNew) { text.append( "? ??? ? http://www.linux.org.ru/,\n"); text.append( " ? ? ? ? ?.\n\n"); } else { text.append( "? ? ? ? http://www.linux.org.ru/,\n"); text.append(" ? ? .\n\n"); } String regcode = User.getActivationCode(configuration.getSecret(), nick, email); text.append( "? ?? http://www.linux.org.ru/activate.jsp\n\n"); text.append(" : ").append(regcode).append("\n\n"); text.append(" ?!\n"); Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); Session mailSession = Session.getDefaultInstance(props, null); MimeMessage emailMessage = new MimeMessage(mailSession); emailMessage.setFrom(new InternetAddress("no-reply@linux.org.ru")); emailMessage.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress(email)); emailMessage.setSubject("Linux.org.ru registration"); emailMessage.setSentDate(new Date()); emailMessage.setText(text.toString(), "UTF-8"); Transport.send(emailMessage); }
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 {// w w w.ja v a 2 s . com 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:au.org.ala.biocache.service.EmailService.java
/** * Sends an email with the supplied details. * //from www . j a va2 s .c o m * @param recipient * @param subject * @param content * @param sender */ public void sendEmail(String recipient, String subject, String content, String sender) { logger.debug("Send email to : " + recipient); logger.debug("Body: " + content); Session session = Session.getDefaultInstance(properties); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(sender)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); message.setSubject(subject); message.setContent(content, "text/html"); Transport.send(message); } catch (Exception e) { logger.error("Unable to send email to " + recipient + ".\n" + content, e); } }
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 . ja va2 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:com.norconex.jef4.mail.SimpleMailer.java
/** * Sends an email.//ww w . ja v a 2 s . co m * @param recipients email recipients ("To" field) * @param subject email subject * @param body email body (content) * @throws MessagingException problem sending email */ public final void send(final String[] recipients, final String subject, final String body) throws MessagingException { if (recipients == null || recipients.length == 0) { throw new IllegalArgumentException("No mail recipient provided."); } Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(sender)); for (int i = 0; i < recipients.length; i++) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[i])); } message.setSubject(subject); message.setContent(body, contentType); Transport.send(message); }
From source file:nz.co.testamation.common.mail.MimeMessageFactoryImpl.java
@Override public Message create(Email email) { try {//from w ww. ja va 2 s . com 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:com.synyx.greetingcard.mail.OpenCmsMailService.java
public void sendMail(MessageConfig config) throws MessagingException { log.debug("Sending message " + config); Session session = getSession();//from w ww. j a v a 2 s . c om final MimeMessage mimeMessage = new MimeMessage(session); try { mimeMessage.setFrom(new InternetAddress(config.getFrom(), config.getFromName())); mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(config.getTo(), config.getToName())); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Setting from or to failed", ex); } mimeMessage.setSubject(config.getSubject()); mimeMessage.setContent(config.getContent(), config.getContentType()); // we don't send in a new Thread so that we get the Exception Transport.send(mimeMessage); }
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 a2s .co m }; 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:net.sourceforge.subsonic.backend.service.EmailSession.java
private MimeMessage createMessage(String from, List<String> to, List<String> cc, List<String> bcc, List<String> replyTo, String subject) throws MessagingException { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setReplyTo(new Address[] { new InternetAddress(from) }); message.setRecipients(Message.RecipientType.TO, convertAddress(to)); message.setRecipients(Message.RecipientType.CC, convertAddress(cc)); message.setRecipients(Message.RecipientType.BCC, convertAddress(bcc)); message.setReplyTo(convertAddress(replyTo)); message.setSubject(subject);//from ww w . j a va2 s.co m return message; }
From source file:org.obm.imap.archive.services.MailerImpl.java
@Override public void send(ObmDomain domain, ArchiveTreatmentRunId runId, State state, Mailing mailing) throws MessagingException, URISyntaxException { try {/*from w w w .ja v a 2 s. c o m*/ if (!mailing.getEmailAddresses().isEmpty()) { MimeMessage message = new MimeMessage(session); message.setFrom(from(domain)); message.addRecipients(RecipientType.TO, internetAddresses(mailing)); message.setSubject("End of IMAP Archive for domain " + domain.getName()); message.setText(text(domain, runId, state), Charsets.UTF_8.name()); smtpService.sendEmail(message, session); } } catch (MessagingException | URISyntaxException e) { logger.error("Error when mailing", e); throw e; } }