Java Code Examples for org.springframework.mail.javamail.MimeMessageHelper#setBcc()
The following examples show how to use
org.springframework.mail.javamail.MimeMessageHelper#setBcc() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringJavaEmailSender.java From DataSphereStudio with Apache License 2.0 | 7 votes |
private MimeMessage parseToMimeMessage(Email email) { MimeMessage message = javaMailSender.createMimeMessage(); try { MimeMessageHelper messageHelper = new MimeMessageHelper(message, true); if(StringUtils.isBlank(email.getFrom())) { messageHelper.setFrom(SendEmailAppJointConfiguration.DEFAULT_EMAIL_FROM().getValue()); } else { messageHelper.setFrom(email.getFrom()); } messageHelper.setSubject(email.getSubject()); messageHelper.setTo(email.getTo()); messageHelper.setCc(email.getCc()); messageHelper.setBcc(email.getBcc()); for(Attachment attachment: email.getAttachments()){ messageHelper.addAttachment(attachment.getName(), new ByteArrayDataSource(attachment.getBase64Str(), attachment.getMediaType())); } messageHelper.setText(email.getContent(), true); } catch (Exception e) { logger.error("Send mail failed", e); } return message; }
Example 2
Source File: MailPlugin.java From iotplatform with Apache License 2.0 | 6 votes |
private void sendMail(SendMailActionMsg msg) throws MessagingException { log.debug("Sending mail {}", msg); MimeMessage mailMsg = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mailMsg, "UTF-8"); helper.setFrom(msg.getFrom()); helper.setTo(msg.getTo()); if (!StringUtils.isEmpty(msg.getCc())) { helper.setCc(msg.getCc()); } if (!StringUtils.isEmpty(msg.getBcc())) { helper.setBcc(msg.getBcc()); } helper.setSubject(msg.getSubject()); helper.setText(msg.getBody()); mailSender.send(helper.getMimeMessage()); log.debug("Mail sent {}", msg); }
Example 3
Source File: MailUtil.java From PhrackCTF-Platform-Personal with Apache License 2.0 | 6 votes |
@Async public void mailTo(String[] targetuser,String title,String content,JavaMailSender javaMailSender) {//邮件功能 try { MimeMessage mimeMsg = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8"); helper.setText(content, true); helper.setBcc(targetuser); helper.setSubject(title); String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom"); String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname"); helper.setFrom(authormail,authorname); javaMailSender.send(mimeMsg); log.info("Mail send to "+Arrays.toString(targetuser)); } catch(Exception e) { e.printStackTrace(); } }
Example 4
Source File: EmailNotificationServiceImpl.java From podcastpedia-web with MIT License | 6 votes |
public void sendContactNotification(final ContactForm contactForm) { MimeMessagePreparator preparator = new MimeMessagePreparator() { @SuppressWarnings({ "rawtypes", "unchecked" }) public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setTo(configService.getValue("EMAIL_TO_CONTACT_MESSAGE")); message.setBcc("[email protected]"); message.setFrom(new InternetAddress(contactForm.getEmail())); message.setSubject("New contact message " + contactForm.getTopic()); message.setReplyTo(contactForm.getEmail()); message.setSentDate(new Date()); Map model = new HashMap(); model.put("newMessage", contactForm); String text = VelocityEngineUtils.mergeTemplateIntoString( velocityEngine, "velocity/newContactMessageToAdmin.vm", "UTF-8", model); message.setText(text, true); } }; this.mailSender.send(preparator); }
Example 5
Source File: EmailNotificationServiceImpl.java From podcastpedia-web with MIT License | 6 votes |
public void sendSuggestPodcastNotification(final SuggestedPodcast suggestedPodcast) { MimeMessagePreparator preparator = new MimeMessagePreparator() { @SuppressWarnings({ "rawtypes", "unchecked" }) public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setTo(configService.getValue("EMAIL_TO_SUGGEST_PODCAST")); message.setBcc("[email protected]"); message.setFrom(new InternetAddress(suggestedPodcast.getEmail()) ); message.setSubject("New suggested podcast"); message.setSentDate(new Date()); Map model = new HashMap(); model.put("newPodcast", suggestedPodcast); String text = VelocityEngineUtils.mergeTemplateIntoString( velocityEngine, "velocity/suggestPodcastNotificationMessage.vm", "UTF-8", model); message.setText(text, true); } }; mailSender.send(preparator); }
Example 6
Source File: EmailServiceImpl.java From DimpleBlog with Apache License 2.0 | 5 votes |
@Override public void sendHtmlMail(String to, String title, String content) { EmailSetting emailSetting = configService.selectConfigByConfigKey(ConfigKey.CONFIG_KEY_EMAIL_SETTING, EmailSetting.class); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setUsername(emailSetting.getUser()); mailSender.setHost(emailSetting.getHost()); mailSender.setDefaultEncoding("utf-8"); mailSender.setPassword(emailSetting.getPassword()); mailSender.setPort(emailSetting.getPort()); Properties properties = new Properties(); properties.put("mail.smtp.host", emailSetting.getHost()); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.socketFactory.fallback", "false"); // 只处理SSL的连接,对于非SSL的连接不做处理 properties.put("mail.smtp.port", emailSetting.getPort()); properties.put("mail.smtp.socketFactory.port", emailSetting.getPort()); properties.put("mail.smtp.ssl.enable", true); Session session = Session.getInstance(properties); MimeMessage mimeMessage = mailSender.createMimeMessage(); try { MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setFrom(emailSetting.getFromEmail()); mimeMessageHelper.setTo(to); if (StringUtils.isNotEmpty(emailSetting.getStationmasterEmail())) { mimeMessageHelper.setBcc(emailSetting.getStationmasterEmail()); } mimeMessageHelper.setSubject(title); mimeMessageHelper.setText(content, true); mailSender.setSession(session); mailSender.send(mimeMessage); } catch (MessagingException e) { log.error(e.getMessage(), e); } }
Example 7
Source File: EmailService.java From zhcet-web with Apache License 2.0 | 5 votes |
private void setBasicInfo(MimeMessageHelper mailMessage, String from, String to, String subject, String[] bcc) throws MessagingException { if (isDisabled()) return; mailMessage.setSubject(subject); mailMessage.setFrom(from); mailMessage.setTo(to); if (bcc != null) mailMessage.setBcc(bcc); }
Example 8
Source File: EmailJob.java From quartz-manager with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void sendEmail(JobDataMap map) { String subject = map.getString("subject"); String messageBody = map.getString("messageBody"); List<String> to = (List<String>) map.get("to"); List<String> cc = (List<String>) map.get("cc"); List<String> bcc = (List<String>) map.get("bcc"); MimeMessage message = mailSender.createMimeMessage(); try { MimeMessageHelper helper = new MimeMessageHelper(message, false); for(String receipient : to) { helper.setFrom("[email protected]", "Julius from Dynamic Quartz"); helper.setTo(receipient); helper.setSubject(subject); helper.setText(messageBody); if(!isEmpty(cc)) helper.setCc(cc.stream().toArray(String[]::new)); if(!isEmpty(bcc)) helper.setBcc(bcc.stream().toArray(String[]::new)); mailSender.send(message); } } catch (MessagingException | UnsupportedEncodingException e) { log.error("An error occurred: {}", e.getLocalizedMessage()); } }
Example 9
Source File: MailClientUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
public static void send( String from, String to, String cc[], String bcc[], String fileNames[], File files[], String subject, String text) throws MailException, Exception { if (mailSender==null) { throw new Exception("null mailSender!"); } if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) { throw new Exception("from and to is required!"); } if (fileNames!=null && files!=null) { if (fileNames.length != files.length) { throw new Exception("File parameter error!"); } } MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING); helper.setFrom(from); helper.setTo( to.endsWith(";") ? to.substring(0, to.length()-1) : to ); helper.setSubject(subject); helper.setText(text, true); if (null!=cc && cc.length>0) { helper.setCc(cc); } if (null!=bcc && bcc.length>0) { helper.setBcc(bcc); } for (int i=0; fileNames!=null && i<fileNames.length; i++) { helper.addAttachment(fileNames[i], files[i]); } mailSender.send(message); }
Example 10
Source File: WaltzEmailer.java From waltz with Apache License 2.0 | 5 votes |
public void sendEmail(String subject, String body, String[] to) { if (this.mailSender == null) { LOG.warn("Not sending email. No mailer provided."); return; } Checks.checkNotEmpty(subject, "subject cannot be empty"); Checks.checkNotEmpty(body, "body cannot be empty"); Checks.checkNotEmpty(to, "to cannot be empty"); Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty"); MimeMessagePreparator preparator = mimeMessage -> { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true); message.setSubject(subject); message.setFrom(fromEmail); message.setBcc(to); message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png")); message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png")); Map model = new HashMap(); model.put("body", body); Configuration cfg = new Configuration(Configuration.VERSION_2_3_23); try(InputStreamReader templateReader = new InputStreamReader(IOUtilities .getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION) .getInputStream())) { Template template = new Template("template", templateReader, cfg); String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model); message.setText(text, true); } }; this.mailSender.send(preparator); }
Example 11
Source File: EmailServiceImpl.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
public void sendEmailNotification(final EmailNotification emailNotification) { if (enabled && emailNotification.getTo() != null && emailNotification.getTo().length > 0) { try { final MimeMessageHelper mailMessage = new MimeMessageHelper(mailSender.createMimeMessage(), true, StandardCharsets.UTF_8.name()); final Template template = freemarkerConfiguration.getTemplate(emailNotification.getTemplate()); String content = processTemplateIntoString(template, emailNotification.getParams()); content = content.replaceAll("<br />", "<br />"); final String from = isNull(emailNotification.getFrom()) || emailNotification.getFrom().isEmpty() ? defaultFrom : emailNotification.getFrom(); if (isEmpty(emailNotification.getFromName())) { mailMessage.setFrom(from); } else { mailMessage.setFrom(from, emailNotification.getFromName()); } mailMessage.setTo(emailNotification.getTo()); if (emailNotification.isCopyToSender() && emailNotification.getFrom() != null) { mailMessage.setBcc(emailNotification.getFrom()); } if (emailNotification.getBcc() != null && emailNotification.getBcc().length > 0) { mailMessage.setBcc(emailNotification.getBcc()); } mailMessage.setSubject(format(subject, emailNotification.getSubject())); final String html = addResourcesInMessage(mailMessage, content); LOGGER.debug("Sending an email to: {}\nSubject: {}\nMessage: {}", emailNotification.getTo(), emailNotification.getSubject(), html); mailSender.send(mailMessage.getMimeMessage()); } catch (final Exception ex) { LOGGER.error("Error while sending email notification", ex); throw new TechnicalManagementException("Error while sending email notification", ex); } } }
Example 12
Source File: JavaMailAgent.java From kaif with Apache License 2.0 | 5 votes |
public void prepare(MimeMessage mimeMessage) throws MessagingException { MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, Charsets.UTF_8.toString()); try { messageHelper.setFrom(message.getFrom(), message.getFromName()); } catch (UnsupportedEncodingException e) { throw new MessagingException( "UnsupportedEncodingException while encode 'the name of FROM person'", e); } messageHelper.setTo(message.getTo()); if (message.getBcc() != null) { messageHelper.setBcc(message.getBcc()); } if (message.getCc() != null) { messageHelper.setCc(message.getCc()); } if (message.getReplyTo() != null) { messageHelper.setReplyTo(message.getReplyTo()); } messageHelper.setSubject(message.getSubject()); messageHelper.setText(message.getText()); }
Example 13
Source File: MailUtil.java From PhrackCTF-Platform-Team with Apache License 2.0 | 4 votes |
@Async public void mailTo(String[] targetuser,String title,String content,JavaMailSender javaMailSender) {//邮件功能 try { MimeMessage mimeMsg = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8"); helper.setText(content, true); helper.setBcc(targetuser); helper.setSubject(title); String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom"); String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname"); helper.setFrom(authormail,authorname); javaMailSender.send(mimeMsg); log.info("Mail send to "+Arrays.toString(targetuser)); } catch(Exception e) { e.printStackTrace(); } }
Example 14
Source File: MailComposerImpl.java From yes-cart with Apache License 2.0 | 4 votes |
void composeMessage(final MimeMessage message, final String shopCode, final String locale, final List<String> mailTemplateChain, final String templateName, final String from, final String toEmail, final String ccEmail, final String bccEmail, final Map<String, Object> model) throws MessagingException, IOException, ClassNotFoundException { final MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); helper.setTo(toEmail); helper.setSentDate(new Date()); if (ccEmail != null) { helper.setCc(ccEmail); } if (bccEmail != null) { helper.setBcc(bccEmail); } final String textContent = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".txt", model); final String htmlContent = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".html", model); final String propString = processTemplate(mailTemplateChain, shopCode, locale, templateName, ".properties", model); final Properties prop = new Properties(); if (propString != null) { prop.load(new StringReader(propString)); } helper.setSubject(prop.getProperty("subject")); if (from == null) { helper.setFrom(prop.getProperty("from")); } else { helper.setFrom(from); } final Map<String, byte[]> attachments = collectAttachments(model); composeMessage(helper, textContent, htmlContent, attachments, mailTemplateChain, shopCode, locale, templateName); }
Example 15
Source File: MailComposerImpl.java From yes-cart with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void convertMessage(final Mail mail, final MimeMessage mimeMessage) throws MessagingException, IOException, ClassNotFoundException { final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); helper.setTo(mail.getRecipients()); helper.setSentDate(new Date()); if (mail.getCc() != null) { helper.setCc(mail.getCc()); } if (mail.getBcc() != null) { helper.setBcc(mail.getBcc()); } final String textTemplate = mail.getTextVersion(); final String htmlTemplate = mail.getHtmlVersion(); helper.setSubject(mail.getSubject()); helper.setFrom(mail.getFrom()); if (textTemplate == null || htmlTemplate == null) { if (textTemplate != null) { helper.setText(textTemplate, false); } if (htmlTemplate != null) { helper.setText(htmlTemplate, true); inlineResources(helper, mail); } } else { helper.setText(textTemplate, htmlTemplate); inlineResources(helper, mail); } }
Example 16
Source File: EmailService.java From guardedbox with GNU Affero General Public License v3.0 | 3 votes |
/** * Sends an email. * * @param to Receiver. * @param subject Subject. * @param content HTML Content. */ public void send( String to, String subject, String content) { MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { if (!StringUtils.isEmpty(mailFrom)) mimeMessageHelper.setFrom(mailFrom); mimeMessageHelper.setTo(to); if (!StringUtils.isEmpty(mailBcc)) mimeMessageHelper.setBcc(mailBcc); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(content, true); } catch (MessagingException e) { throw new MailSendException("Error setting the email attributes", e); } javaMailSender.send(mimeMessage); }