private void sendEmail(String from, String to, String subject, String message) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(from); mailMessage.setTo(to.split(",")); mailMessage.setSubject(subject); mailMessage.setText(message); mailSender.send(mailMessage); }
private boolean handleAlert( final User user, final Alert alert, final String subject, final String message, final Long creatorId) { List<UserContact> contacts = user.getContactInfo(); if (contacts == null) { return false; } // get the user's preferred contact method UserContact contact = null; for (UserContact aContact : contacts) { if (aContact.getPriority() == null) { continue; } if (contact == null || (aContact.getPriority() < contact.getPriority())) { contact = aContact; } } if (contact == null) { log.debug( "User {} has no preferred contact method, not sending alert {}", user.getUsername(), alert.getAlertType()); return false; } // send the user an alert... only email supported currently SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(contact.getContact()); msg.setText(message); switch (contact.getKind()) { case MOBILE: // treat as an email to their mobile number // TODO: extract out mobile SMS handling to configurable service msg.setTo(contact.getContact().replaceAll("\\D", "") + "@isms.net.nz"); msg.setFrom("*****@*****.**"); break; case EMAIL: msg.setSubject(subject); msg.setFrom("*****@*****.**"); break; default: log.debug( "User {} contact type {} not supported in alerts", user.getUsername(), contact.getKind()); return false; } sendMailMessage(msg, creatorId); return true; }
private static void sendMail(String str, String sendTo, String subject) { if (javaMail == null) { try { javaMail = new JavaMailSenderImpl(); javaMail.setUsername(MAIL_USERNAME); javaMail.setPassword(MAIL_PASSWORD); Properties prop = new Properties(); prop.setProperty("mail.smtp.auth", "true"); prop.setProperty("mail.debug", "true"); prop.setProperty("mail.smtp.socketFactory.port", "465"); prop.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); prop.setProperty("mail.smtp.socketFactory.fallback", "false"); prop.setProperty("mail.smtp.port", "465"); prop.setProperty("host", MAIL_SMTP); javaMail.setJavaMailProperties(prop); javaMail.setProtocol("smtp"); } catch (Exception ex) { ex.printStackTrace(); } } // 初始化邮件信息 SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(MAIL_USERNAME + "@" + MAIL_HOST); message.setTo(sendTo); message.setSubject(subject); message.setText(str); javaMail.send(message); }
private void sendEmail(User user, String subject, String text) { if (host != null && !host.equals("")) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(host); sender.setPort(port); sender.setUsername(smtpUser); sender.setPassword(smtpPassword); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(user.getLogin()); message.setFrom(from); message.setSubject(subject); message.setText(text); try { sender.send(message); if (log.isDebugEnabled()) { log.debug("Sent e-mail to User '" + user.getLogin() + "'!"); } } catch (MailException e) { log.warn("Warning! SMTP server error, could not send e-mail."); if (log.isDebugEnabled()) { log.debug("SMTP Error : " + e.getMessage()); log.debug("Did you configure your SMTP settings in /META-INF/tatami/tatami.properties ?"); } } } else { log.debug("SMTP server is not configured in /META-INF/tatami/tatami.properties"); } }
@Bean public SimpleMailMessage templateMessage() { SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom((String) projectSettings().getMailerSettings().get("from")); return simpleMailMessage; }
private SimpleMailMessage constructEmail(String subject, String body, User user) { final SimpleMailMessage email = new SimpleMailMessage(); email.setSubject(subject); email.setText(body); email.setTo(user.getEmail()); email.setFrom(env.getProperty("support.email")); return email; }
/* * (non-Javadoc) * @see com.sogeti.webshop.services.IMailService#sendMail(java.lang.String, java.lang.String, java.lang.String) */ @Override public void sendMail(String from, String to, String subject, String body) { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(from); message.setTo(to); message.setSubject(subject); message.setText(body); mailSender.send(message); }
@Bean public SimpleMailMessage citibankCreditCardPromotionMailMessage() { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(mailForm); mailMessage.setTo(mailCitibankCreditCardPromotionTo); mailMessage.setReplyTo(mailReplyTo); mailMessage.setSubject(mailCitibankCreditCardPromotionSubject); return mailMessage; }
private void sendUpgradeEMail(User user) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setFrom("*****@*****.**"); mailMessage.setSubject("Upgrade 안내"); mailMessage.setText("사용자님의 등급이 " + user.getLevel().name()); this.mailSender.send(mailMessage); }
public void sendMail(String from, String to, String subject, String msg) { SimpleMailMessage message = new SimpleMailMessage(); System.out.println("inside mail sendmail"); message.setFrom(from); message.setTo(to); message.setSubject(subject); message.setText(msg); mailSender.send(message); }
@Test @Ignore public void doSendMail() { SimpleMailMessage email = new SimpleMailMessage(); email.setTo("*****@*****.**"); email.setFrom("*****@*****.**"); email.setSubject("DTS Test"); email.setText("Hello"); javaMailSender.send(email); }
/** 发送模板邮件 */ public void sendWithTemplate(String message) { SystemPropertyUtil.init( MailSenderService.class.getResource("/" + "system.properties").getFile()); String subject = SystemPropertyUtil.getInstance().getProperty("email.subject"); String from = SystemPropertyUtil.getInstance().getProperty("email.from"); String userName = SystemPropertyUtil.getInstance().getProperty("email.system"); String sendTo = SystemPropertyUtil.getInstance().getProperty("email.send.to"); Map<String, String> model = new HashMap<String, String>(); model.put("username", userName); model.put("from", from); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // model.put("Date", simpleDateFormat.format(new Date())); model.put("subject", subject); model.put("item", sendTo); model.put("message", message); JavaMailSender mailSender = (JavaMailSender) applicationContext.getBean("mailSender"); VelocityEngine velocityEngine = (VelocityEngine) applicationContext.getBean("velocityEngine"); SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom(from); // 发送人,从配置文件中取得 simpleMailMessage.setSubject(subject); // 设置收件人邮箱 String[] toEmailArray = sendTo.split(";"); List<String> toEmailList = new ArrayList<String>(); if (null == toEmailArray || toEmailArray.length <= 0) { throw new RuntimeException("收件人邮箱不得为空!"); } else { for (String s : toEmailArray) { if (!s.equals("")) { toEmailList.add(s); } } if (null == toEmailList || toEmailList.size() <= 0) { throw new RuntimeException("收件人邮箱不得为空!"); } else { toEmailArray = new String[toEmailList.size()]; for (int i = 0; i < toEmailList.size(); i++) { toEmailArray[i] = toEmailList.get(i); } simpleMailMessage.setTo(toEmailArray); // 收件人 } } String result = null; try { result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "mail.vm", "UTF-8", model); } catch (Exception e) { log.error("Can't send the mail!", e); } simpleMailMessage.setText(result); mailSender.send(simpleMailMessage); log.debug("邮件发送完成"); }
@Override protected void doNotify(ClientApplicationStatusChangedEvent event) { EvaluationContext context = new StandardEvaluationContext(event); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(to); message.setFrom(from); message.setSubject(subject.getValue(context, String.class)); message.setText(text.getValue(context, String.class)); message.setCc(cc); sender.send(message); }
private final SimpleMailMessage constructEmailMessage( final OnRegistrationCompleteEvent event, final User user, final String token) { final String recipientAddress = user.getEmail(); final String subject = "Registration Confirmation"; final String confirmationUrl = event.getAppUrl() + "/regitrationConfirm.html?token=" + token; final String message = messages.getMessage("message.regSucc", null, event.getLocale()); final SimpleMailMessage email = new SimpleMailMessage(); email.setTo(recipientAddress); email.setSubject(subject); email.setText(message + " \r\n" + confirmationUrl); email.setFrom(env.getProperty("support.email")); return email; }
private void send(String subject, String content) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(supportEmail); mailMessage.setReplyTo(supportEmail); mailMessage.setFrom(supportEmail); mailMessage.setSubject(subject); mailMessage.setText(content); try { // javaMailSender.send(mailMessage); } catch (MailException e) { e.printStackTrace(); } }
@Override public void sendTextMail(final MailMetaData mailMetaData, final String text) { if (suppressMail) { return; } final SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom( new StringBuilder() .append(mailMetaData.getFromName()) .append(" <") .append(mailMetaData.getFromAddress()) .append(">") .toString()); mailMessage.setSubject(mailMetaData.getSubject()); mailMessage.setReplyTo(mailMetaData.getReplyTo()); if (mailMetaData.getCcAddresses() != null && mailMetaData.getCcAddresses().size() > 0) { mailMessage.setCc( (String[]) mailMetaData .getCcAddresses() .toArray(new String[mailMetaData.getCcAddresses().size()])); } if (mailMetaData.getBccAddresses() != null && mailMetaData.getBccAddresses().size() > 0) { mailMessage.setBcc( (String[]) mailMetaData .getBccAddresses() .toArray(new String[mailMetaData.getBccAddresses().size()])); } if (mailMetaData.getToAddresses() != null && mailMetaData.getToAddresses().size() > 0) { mailMessage.setTo( (String[]) mailMetaData .getToAddresses() .toArray(new String[mailMetaData.getToAddresses().size()])); } mailMessage.setText(text); try { mailSender.send(mailMessage); } catch (MailException e) { throw new SendMailException( new StringBuilder() .append("Error sending mail: ") .append(mailMetaData.toString()) .toString(), e); } }
public void sendEmailNotification(String from, String to) { try { logger.info("Sending email to " + to); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("OnionSquare Registration <*****@*****.**>"); message.setTo(to); message.setSubject("Onionsquare | No Sales Activity Email Notification"); message.setText( "We have noticed no sales activity of your store since 5 months. We suggest you to take appropriate actions to continue your store. Your store will be deactivated after one months of this email if we notice no sales of your store during this period. Thank you."); logger.info("Sending no sales activity email notification to " + to); mailSender.send(message); logger.info("Email sent to" + to); } catch (Exception e) { logger.info("Mail cannot be send due to internal error"); } }
@RequestMapping( value = "/sendmessage", method = RequestMethod.POST, produces = "application/json") @ResponseBody public Map<String, Object> sendMessages( Principal principal, @RequestBody Map<String, Object> data) { String text = (String) data.get("text"); String name = (String) data.get("name"); String email = (String) data.get("email"); // String username= (String)data.get("username"); User msgSender = usersService.getUserByEmail(email); String username = msgSender.getUsername(); // Integer target= (Integer)data.get("target"); Message message = new Message(); message.setName(principal.getName()); // siuntejo message.setUsername(username); // Gavejo message.setEmail(email); message.setContent(text); message.setSubject("Reply from: " + name); System.out.println(name + " " + email + " " + text); SimpleMailMessage mail = new SimpleMailMessage(); mail.setFrom("*****@*****.**"); mail.setTo(email); mail.setSubject("Reply from: " + name); mail.setText(text); usersService.sendMessage(message); try { mailSender.send(mail); } catch (Exception e) { e.printStackTrace(); System.out.println("Cant send"); } Map<String, Object> reply = new HashMap<String, Object>(); reply.put("success", true); // reply.put("target", target); return reply; }
@Override public void sendMail( final String _fromAddr, final String _toAddr, final String _subject, final String _body) { LOG.info("Sending mail from: " + _fromAddr); LOG.info("Sending mail to: " + _toAddr); LOG.info("Sending mail with subject: " + _subject); LOG.info("Sending body with length: " + (_body == null ? 0 : _body.length())); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(_toAddr); message.setFrom(_fromAddr); message.setText(_body); message.setSubject(_subject); send(message); }
public SimpleMailMessage mergeSimpleMessage(String to, Map<String, Object> model) { // render text of mail from velocity template with the data String text = null; try { text = renderText(model); } catch (VelocityException e) { log.error(e); e.printStackTrace(); } // mail message setting SimpleMailMessage message = new SimpleMailMessage(); message.setSubject(getSubject()); message.setFrom(getFrom()); message.setTo(to); message.setText(text); return message; }
public void sendMail( String fromEmail, String toEmail, String ccEmail, String subject, String body) throws MailException { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(fromEmail); message.setTo(toEmail); if (StringUtils.isNotEmpty(ccEmail)) { message.setCc(ccEmail); } message.setSubject(subject); message.setText(body); try { mailSender.send(message); System.out.println("Mail sent"); } catch (MailException e) { e.printStackTrace(); System.out.println("Mail failed"); throw e; } }
public void sendMail(User user, String email, String subject, String templateUrl) throws Exception { SimpleMailMessage message = new SimpleMailMessage(); String hostname = InetAddress.getLocalHost().getHostAddress(); message.setFrom(email); message.setTo(user.getEmail()); message.setSubject(subject); Template template = null; template = velocityEngine.getTemplate(templateUrl); VelocityContext velocityContext = new VelocityContext(); velocityContext.put("user", user); velocityContext.put("hostname", hostname); StringWriter stringWriter = new StringWriter(); template.merge(velocityContext, stringWriter); message.setText(stringWriter.toString()); mailSender.send(message); }