List of usage examples for org.springframework.mail SimpleMailMessage setText
@Override public void setText(String text)
From source file:org.openregistry.core.service.DefaultEmailIdentifierNotificationStrategy.java
public void notifyPerson(Person person, Role role, Type addressType, Identifier idToNotifyAbout, String activationKeyString) throws IllegalArgumentException, IllegalStateException { if (person == null) { throw new IllegalArgumentException("Person must be specified"); }//from w ww . j av a 2s .c o m if (idToNotifyAbout == null) { throw new IllegalArgumentException("Identifier must be specified"); } Name officialName = person.getOfficialName(); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(findEmailAddressesForNotification(person, role, addressType)); msg.setFrom(messageSource.getMessage("activation.notify.from", null, null)); msg.setSubject(messageSource.getMessage("activation.notify.subject", null, null)); String greeting = (officialName == null) ? "" : officialName.getFormattedName(); msg.setText(messageSource.getMessage("activation.notify.body", new String[] { greeting, idToNotifyAbout.getValue(), activationKeyString }, null)); mailSender.send(msg); }
From source file:com.admob.rocksteady.reactor.Alerting.java
/** * Handle the triggered event/*from ww w. j a va2s . c o m*/ * * @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:net.bafeimao.umbrella.web.test.MailTests.java
/** * SpringMailSender???//from w ww .j a v a 2s. c o m */ @Test public void testSendMail() { // ? SimpleMailMessage mailMessage = new SimpleMailMessage(); // ?? // String[] array = new String[] {"sun111@163.com","sun222@sohu.com"}; // mailMessage.setTo(array); mailMessage.setTo(" 29283212@qq.com"); mailMessage.setFrom("29283212@qq.com"); mailMessage.setSubject("???!"); mailMessage.setText(" ????"); // ?? senderImpl.send(mailMessage); System.out.println(" ???.. "); }
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 . j ava 2 s . c o 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:com.springsource.greenhouse.reset.ResetPasswordMailMessageConverter.java
public SimpleMailMessage convert(ResetPasswordRequest request) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom("Greenhouse <noreply@springsource.com>"); mailMessage.setTo(request.getAccount().getEmail()); StringTemplate textTemplate;// w w w .ja v a2s .co m mailMessage.setSubject("Reset your Greenhouse password"); textTemplate = resetTemplateFactory.getStringTemplate(); textTemplate.put("firstName", request.getAccount().getFirstName()); textTemplate.put("resetUrl", resetUriTemplate.expand(request.getToken())); mailMessage.setText(textTemplate.render()); return mailMessage; }
From source file:cz.muni.fi.mir.services.MailServiceImpl.java
@Override public void sendMail(String from, String receiver, String subject, String message) throws IllegalArgumentException { if (isEnabled()) { if (StringUtils.isEmpty(receiver)) { throw new IllegalArgumentException("Receiver of email is not set. to value is [" + receiver + "]"); }/*ww w . j ava2 s . c o m*/ if (StringUtils.isEmpty(subject)) { throw new IllegalArgumentException( "Subject of email is not set. subject value is [" + subject + "]"); } if (StringUtils.isEmpty(message)) { throw new IllegalArgumentException( "Message of email is not set. message value is [" + message + "]"); } SimpleMailMessage mailMessage = new SimpleMailMessage(); if (StringUtils.isEmpty(from)) { mailMessage.setFrom(sender); } else { mailMessage.setFrom(from); } if (StringUtils.isEmpty(subjectPrefix)) { mailMessage.setSubject(subjectPrefix + subject); } else { mailMessage.setSubject(subject); } mailMessage.setTo(receiver); mailMessage.setText(message); mailSender.send(mailMessage); } }
From source file:com.healthcit.cacure.utils.MailSendingService.java
/** * Sends a notification email, that a section has been submitted for review * * @param form the form, which is submitted for review * @param toEmail the recipient - the intended recipients are ROLE_APPROVERs */// ww w . j a v a 2 s . com public void sendSubmittedSectionNotification(QuestionnaireForm form, String toEmail, String webAppUri) { SimpleMailMessage message = new SimpleMailMessage(submittedSectionNotificationTemplate); StringBuilder emailText = new StringBuilder(submittedSectionNotificationTemplate.getText()); //TODO: DEVISE A BETTER WAY OF OBTAINING THE WEB-APP PATH StringUtils.replace(emailText, WEB_APP_PATH_IDENTIFIER, webAppUri); StringUtils.replace(emailText, MODULE_ID_IDENTIFIER, form.getModule().getId().toString()); StringUtils.replace(emailText, FORM_ID_IDENTIFIER, form.getId().toString()); message.setText(emailText.toString()); message.setTo(toEmail); try { if (logger.isDebugEnabled()) { logger.debug("Sending section submitted notification mail to " + toEmail); } mailSender.send(message); } catch (MailException me) { logger.error("Failed sending section submitted notification mail", me); } }
From source file:me.j360.base.service.common.SimpleMailService.java
/** * ??./* w w w . ja va 2 s . c o m*/ */ public void sendNotificationMail(String userName) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("?<system@smart-sales.cn>"); msg.setTo("xuminwlt2008@163.com"); msg.setSubject("?"); //id String url = "http://www.smart-sales.cn/smartsales/com/email.action?keyId=1"; // ???? String content = String.format(textTemplate, userName, new Date(), url); msg.setText(content); /*try { mailSender.send(msg); if (logger.isInfoEnabled()) { logger.info("??{}", StringUtils.join(msg.getTo(), ",")); } } catch (Exception e) { logger.error("??", e); }*/ }
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);/*from w w w .j av a 2s. c o m*/ mailMessage.setText(message); mailSender.send(mailMessage); }
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) {/* ww w . java 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.."); }