List of usage examples for org.springframework.mail SimpleMailMessage setSubject
@Override public void setSubject(String subject)
From source file:com.edgenius.core.service.impl.MailEngineService.java
public void sendPlainMail(SimpleMailMessage msg, String templateName, Map model) { String content = generateContent(templateName, model); String subject = generateContent(getSubjectName(templateName), model); try {// w w w . ja v a2s . com msg.setText(content); if (!StringUtils.isBlank(subject)) msg.setSubject(subject); mailSender.send(msg); } catch (Exception e) { log.error("Send plain mail failed on {}", e.toString(), e); log.info("Message subject: {}", subject); log.info("Message content: {}", content); } }
From source file:com.admob.rocksteady.reactor.Alerting.java
/** * Handle the triggered event//from w w w.j a v a2s . c om * * @param newEvents the new events in the window * @param oldEvents the old events in the window */ public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents == null) { return; } Integer i = 0; Date sqlDate = new Date(); for (EventBean newEvent : newEvents) { i++; try { String msg = ""; String _subject = ""; // This is how string comparison is done in JAVA, not == if (type.equals("log")) { String name = newEvent.get("name").toString(); // String value = newEvent.get("value").toString(); String error = newEvent.get("error").toString(); String count = newEvent.get("count").toString(); msg = name + " - " + error + " - " + count + " errors."; } else if (type.equals("latency_single")) { String hostname = newEvent.get("hostname").toString(); String name = newEvent.get("name").toString(); String value = newEvent.get("value").toString(); String colo = newEvent.get("colo").toString(); String app = newEvent.get("app").toString(); String graphiteTs = newEvent.get("timestamp").toString(); msg = colo + " - " + hostname + " - " + app + " - " + name + " - " + value; Threshold threshold = new Threshold(); threshold.setName(name); threshold.setHostname(hostname); threshold.setColo(colo); threshold.setApp(app); threshold.setGraphiteTs(graphiteTs); threshold.setGraphiteValue(value); threshold.setCreateOn(sqlDate); threshold.persist(); msg = msg + "\n" + "http://" + rsweb + "/rsweb/threshold.php?id=" + String.valueOf(threshold.getId()); _subject = this.subject + " - " + colo + " - " + hostname; } else if (type.equals("latency_multi")) { Metric l = (Metric) newEvent.get("latency"); String l_hostname = l.getHostname(); String l_value = l.getValue().toString(); String l_name = l.getName(); Metric w = (Metric) newEvent.get("win"); String name = w.getName(); String value = w.getValue().toString(); String ts = w.getTimestamp().toString(); String colo = w.getColo(); String hostname = w.getHostname(); String app = w.getApp(); msg = l_hostname + " - " + l_name + " - " + l_value + " - " + app + " - " + name + " - " + value + " - " + ts; // Persistent the threshold cross event Threshold threshold = new Threshold(); threshold.setName(name); threshold.setHostname(hostname); threshold.setColo(colo); threshold.setApp(app); threshold.setGraphiteTs(ts); threshold.setGraphiteValue(value); threshold.setCreateOn(sqlDate); threshold.persist(); } else if (type.equals("deploy")) { String new_revision = newEvent.get("revision").toString(); String colo = newEvent.get("colo").toString(); String hostname = newEvent.get("hostname").toString(); String app = newEvent.get("app").toString(); Revision revision = new Revision(); revision.setHostname(hostname); revision.setColo(colo); revision.setApp(app); revision.setCreateOn(sqlDate); revision.setRevision(new_revision); revision.persist(); msg = "Revision changed on " + colo + " " + hostname + " to " + new_revision; } else if (type.equals("test")) { // String hostname = newEvent.get("hostname").toString(); String colo = newEvent.get("colo").toString(); // String app = newEvent.get("app").toString(); // String timestamp = newEvent.get("timestamp").toString(); // String revision = newEvent.get("revision").toString(); // String diff = newEvent.get("diff").toString(); String value = newEvent.get("value").toString(); String name = newEvent.get("name").toString(); msg = colo + " - " + name + " - " + value; } else if (type.equals("averagedThreshold")) { DecimalFormat df = new DecimalFormat("#.##"); String colo = newEvent.get("colo").toString(); String app = newEvent.get("app").toString(); String value = df.format(newEvent.get("value")); String name = newEvent.get("name").toString(); msg = app + " - " + colo + " - " + name + " - " + value; _subject = this.subject + " - " + msg; } else if (type.equals("count")) { String count = newEvent.get("count").toString(); msg = i + " count: " + count; } else { String name = newEvent.get("name").toString(); String value = newEvent.get("value").toString(); String colo = newEvent.get("colo").toString(); msg = " event triggered - type " + type + " - " + colo + " - " + name + " - " + value; } logger.debug(msg); // This email recipient iisn't empty, we send email out. if (recipients != null & recipients.length > 0) { logger.debug("Email sent"); SimpleMailMessage mail = new SimpleMailMessage(this.templateMessage); mail.setTo(this.recipients); mail.setSubject(_subject); mail.setText(msg); this.mailSender.send(mail); } } catch (Exception e) { logger.error("Trouble. Alert type: " + type + " " + newEvent.toString() + " - " + e.getMessage()); } } }
From source file:cherry.spring.common.foundation.impl.MessageStoreImpl.java
@Override public SimpleMailMessage getMessage(long messageId) { QMailLog a = new QMailLog("a"); SQLQuery querya = queryDslJdbcOperations.newSqlQuery(); querya.from(a).forUpdate();// w w w .ja v a 2s .co m querya.where(a.id.eq(messageId)); querya.where(a.mailStatus.eq(FlagCode.FALSE.code())); querya.where(a.deletedFlg.eq(DeletedFlag.NOT_DELETED.code())); Tuple maillog = queryDslJdbcOperations.queryForObject(querya, new QTuple(a.fromAddr, a.subject, a.body)); if (maillog == null) { return null; } QMailRcpt b = new QMailRcpt("b"); SQLQuery queryb = queryDslJdbcOperations.newSqlQuery(); queryb.from(b).where(b.mailId.eq(messageId)).orderBy(b.id.asc()); List<Tuple> mailrcpt = queryDslJdbcOperations.query(queryb, new QTuple(b.rcptType, b.rcptAddr)); if (mailrcpt.isEmpty()) { return null; } List<String> to = new ArrayList<>(); List<String> cc = new ArrayList<>(); List<String> bcc = new ArrayList<>(); for (Tuple rcpt : mailrcpt) { RcptType type = RcptType.valueOf(rcpt.get(b.rcptType)); if (type == RcptType.TO) { to.add(rcpt.get(b.rcptAddr)); } if (type == RcptType.CC) { cc.add(rcpt.get(b.rcptAddr)); } if (type == RcptType.BCC) { bcc.add(rcpt.get(b.rcptAddr)); } } SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(to.toArray(new String[to.size()])); msg.setCc(cc.toArray(new String[cc.size()])); msg.setBcc(bcc.toArray(new String[bcc.size()])); msg.setFrom(maillog.get(a.fromAddr)); msg.setSubject(maillog.get(a.subject)); msg.setText(maillog.get(a.body)); return msg; }
From source file:org.jasig.schedassist.impl.events.AutomaticAttendeeRemovalApplicationListener.java
@Async @Override//from w w w . ja va 2s . c o m public void onApplicationEvent(AutomaticAttendeeRemovalEvent event) { ICalendarAccount owner = event.getOwner(); VEvent vevent = event.getEvent(); Property removedAttendee = event.getRemoved(); String removedAttendeeEmail = removedAttendee.getValue() .substring(EmailNotificationApplicationListener.MAILTO_PREFIX.length()); deleteEventReminder(owner, vevent, removedAttendeeEmail); SimpleMailMessage message = new SimpleMailMessage(); if (!EmailNotificationApplicationListener.isEmailAddressValid(owner.getEmailAddress())) { message.setFrom(noReplyFromAddress); } else { message.setFrom(owner.getEmailAddress()); } message.setTo(removedAttendeeEmail); Summary summary = vevent.getSummary(); if (summary != null) { message.setSubject(summary.getValue() + " has been updated"); } else { LOG.warn("event is missing summary: " + event); message.setSubject("Appointment has been updated"); } message.setText(constructMessageBody(vevent, removedAttendee, owner.getDisplayName())); LOG.debug("sending message: " + message.toString()); mailSender.send(message); LOG.debug("message successfully sent"); }
From source file:burstcoin.observer.service.NetworkService.java
private void sendMessage(String subject, String message) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(ObserverProperties.getMailReceiver()); mailMessage.setReplyTo(ObserverProperties.getMailReplyTo()); mailMessage.setFrom(ObserverProperties.getMailSender()); mailMessage.setSubject(subject); mailMessage.setText(message);/*from w w w .j a v a 2 s . com*/ mailSender.send(mailMessage); }
From source file:csns.web.controller.SubmissionController.java
private void emailGrade(Submission submission) { if (!StringUtils.hasText(submission.getGrade()) || submission.isGradeMailed()) return;//from w w w . j av a 2s.c om User instructor = SecurityUtils.getUser(); User student = submission.getStudent(); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(instructor.getEmail()); message.setTo(student.getEmail()); String subject = submission.getAssignment().getSection().getCourse().getCode() + " " + submission.getAssignment().getName() + " Grade"; message.setSubject(subject); Map<String, Object> vModels = new HashMap<String, Object>(); vModels.put("grade", submission.getGrade()); String comments = submission.getComments(); vModels.put("comments", comments != null ? comments : ""); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "email.submission.grade.vm", appEncoding, vModels); message.setText(text); try { mailSender.send(message); submission.setGradeMailed(true); submissionDao.saveSubmission(submission); logger.info(instructor.getUsername() + " sent grade to " + student.getEmail()); } catch (MailException e) { logger.warn(instructor.getUsername() + " failed to send grade to " + student.getEmail()); logger.debug(e.getMessage()); } }
From source file:nz.net.orcon.kanban.automation.actions.EmailSenderAction.java
public void sendEmail(String subject, String emailBody, String to, String bcc, String from, String replyTo, String host) {//from www .ja v a 2 s.c o m SimpleMailMessage mailMessage = new SimpleMailMessage(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(host); if (StringUtils.isNotBlank(to)) { mailMessage.setTo(to); } if (StringUtils.isNotBlank(bcc)) { mailMessage.setBcc(bcc); } if (StringUtils.isNotBlank(from)) { mailMessage.setFrom(from); } if (StringUtils.isNotBlank(replyTo)) { mailMessage.setReplyTo(replyTo); } if (StringUtils.isNotBlank(subject)) { mailMessage.setSubject(subject); } mailMessage.setText(emailBody); mailSender.send(mailMessage); logger.info("Email Message has been sent.."); }
From source file:edu.wisc.jmeter.MonitorListener.java
/** * Executes a shell script to send an email. *///from w w w . j av a 2s . co m private void sendEmail(Date now, String subject, String body, String host, Status status) { log("Sending email (" + status + "): " + subject + " - " + body); final SimpleMailMessage message = new SimpleMailMessage(); message.setTo(emailTo); message.setFrom(emailFrom); message.setSubject(subject); message.setText(body); try { this.javaMailSender.send(message); } catch (MailException me) { log("Failed to send email", me); } }
From source file:com.ephesoft.dcma.mail.service.MailServiceImpl.java
@Override public void sendTextMail(final MailMetaData mailMetaData, final String text) { if (suppressMail) { LOGGER.info(//from w w w . jav a2 s. co m "Message suppress switch is on in dcma-mail.properties file. Error mail notfication cann't be send"); return; } setMailProperties(); final SimpleMailMessage mailMessage = new SimpleMailMessage(); if (mailMetaData.getFromAddress() != null) { mailMessage.setFrom(EphesoftStringUtil.concatenate(mailMetaData.getFromName(), MailConstants.LESS_SYMBOL, mailMetaData.getFromAddress(), MailConstants.GREATER_SYMBOL)); } if (null != mailMetaData.getSubject()) { mailMessage.setSubject(mailMetaData.getSubject()); } 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 mailException) { LOGGER.error("Eror while sending mail to configured mail account", mailException); throw new SendMailException( EphesoftStringUtil.concatenate("Error sending mail: ", mailMetaData.toString()), mailException); } LOGGER.info("mail sent successfully"); }
From source file:net.solarnetwork.central.dras.biz.alert.SimpleAlertBiz.java
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; }/*from w w w . j a v a 2 s.c o m*/ // 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("escalation@econz.co.nz"); break; case EMAIL: msg.setSubject(subject); msg.setFrom("solar-adr@solarnetwork.net"); break; default: log.debug("User {} contact type {} not supported in alerts", user.getUsername(), contact.getKind()); return false; } sendMailMessage(msg, creatorId); return true; }