List of usage examples for org.springframework.mail SimpleMailMessage setCc
@Override public void setCc(String... cc)
From source file:ar.com.zauber.commons.spring.mail.EntityManagerMailSenderTest.java
/** test */ @Test/*w w w .j a va2 s. c om*/ public final void testFoo() { final SimpleMailMessage message = new SimpleMailMessage(); message.setBcc("bcc"); message.setCc("cc"); message.setFrom("from"); message.setReplyTo("reply"); message.setText("foo"); message.setTo("a"); ms.send(message); em.flush(); em.clear(); final List<RepositoryMailMessage> l = em.createQuery("from RepositoryMailMessage").getResultList(); assertEquals(1, l.size()); final RepositoryMailMessage m = l.get(0); assertEquals("bcc", m.getBcc()); assertEquals("cc", m.getCc()); assertEquals("from", m.getFrom()); assertEquals("reply", m.getReplyTo()); assertEquals("foo", m.getText()); assertEquals("a", m.getTo()); }
From source file:ar.com.zauber.commons.spring.mail.SessionFactoryMailSenderTest.java
/** test */ @Test/*from ww w.j ava 2 s .com*/ public final void testFoo() { final SimpleMailMessage message = new SimpleMailMessage(); message.setBcc("bcc"); message.setCc("cc"); message.setFrom("from"); message.setReplyTo("reply"); message.setText("foo"); message.setTo("a"); ms.send(message); sessionFactory.getCurrentSession().flush(); sessionFactory.getCurrentSession().clear(); final List<RepositoryMailMessage> l = sessionFactory.getCurrentSession() .createCriteria(RepositoryMailMessage.class).list(); assertEquals(1, l.size()); final RepositoryMailMessage m = l.get(0); assertEquals("bcc", m.getBcc()); assertEquals("cc", m.getCc()); assertEquals("from", m.getFrom()); assertEquals("reply", m.getReplyTo()); assertEquals("foo", m.getText()); assertEquals("a", m.getTo()); }
From source file:de.codecentric.boot.admin.notify.MailNotifierTest.java
@Test public void test_onApplicationEvent() { notifier.notify(new ClientApplicationStatusChangedEvent( Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo.ofUp())); SimpleMailMessage expected = new SimpleMailMessage(); expected.setTo(new String[] { "foo@bar.com" }); expected.setCc(new String[] { "bar@foo.com" }); expected.setFrom("SBA <no-reply@example.com>"); expected.setText("App (-id-)\nstatus changed from DOWN to UP\n\nhttp://health"); expected.setSubject("-id- is UP"); verify(sender).send(eq(expected));/*from w w w . j a v a 2 s. c om*/ }
From source file:cherry.foundation.mail.SimpleMessageStore.java
@Override public long createMessage(String launcherId, String messageName, LocalDateTime scheduledAt, String from, List<String> to, List<String> cc, List<String> bcc, String subject, String body) { long messageId = nextMessageId.getAndIncrement(); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(from);/*from w w w . j a va 2 s . c om*/ message.setTo(toArray(to)); message.setCc(toArray(cc)); message.setBcc(toArray(bcc)); message.setSubject(subject); message.setText(body); MessageRecord record = new MessageRecord(); record.setScheduledAt(scheduledAt); record.setSimpleMailMessage(message); messageRecordMap.put(messageId, record); return messageId; }
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();// ww w . java 2s .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:de.codecentric.boot.admin.notify.MailNotifier.java
@Override protected void doNotify(ClientApplicationStatusChangedEvent event) { EvaluationContext context = new StandardEvaluationContext(event); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(to);//from w w w. j ava 2 s . com message.setFrom(from); message.setSubject(subject.getValue(context, String.class)); message.setText(text.getValue(context, String.class)); message.setCc(cc); sender.send(message); }
From source file:csns.util.EmailUtils.java
public boolean sendTextMail(Email email) { SimpleMailMessage message = new SimpleMailMessage(); message.setSubject(email.getSubject()); message.setText(getText(email));/*from ww w . j a v a 2 s. c o m*/ message.setFrom(email.getAuthor().getPrimaryEmail()); message.setCc(email.getAuthor().getPrimaryEmail()); String addresses[] = getAddresses(email.getRecipients(), email.isUseSecondaryEmail()) .toArray(new String[0]); if (addresses.length > 1) { message.setTo(appEmail); message.setBcc(addresses); } else message.setTo(addresses); mailSender.send(message); logger.info(email.getAuthor().getUsername() + " sent email to " + StringUtils.arrayToCommaDelimitedString(addresses)); return true; }
From source file:mx.unam.pixel.controller.UsuarioController.java
public void recuperaContrasena() { List<Usuario> u = usuarioService.findByCorreo(correoRecuperar); if (u != null || u.size() > 0) { //Aqui se envia correo al usuario investigar si se regresaria null o la lista vacia SimpleMailMessage mail = new SimpleMailMessage(); mail.setTo(u.get(0).getCorreo()); mail.setFrom("pixel.is.pruebas@gmail.com"); mail.setSubject("Muffin"); mail.setCc("pixel_developer@gmail.com"); mail.setText("Tu contrasea es :" + u.get(0).getContrasena()); mailSender.send(mail);/* ww w . j ava2 s . c o m*/ } return; }
From source file:com.ephesoft.dcma.mail.service.MailServiceImpl.java
@Override public void sendTextMail(final MailMetaData mailMetaData, final String text) { if (suppressMail) { LOGGER.info(/* w ww .j a va 2s .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:com.springsource.insight.plugin.mail.MessageSendOperationCollectionAspectTest.java
private void testSendMessage(int port) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(NetworkAddressUtil.LOOPBACK_ADDRESS); sender.setProtocol(JavaMailSenderImpl.DEFAULT_PROTOCOL); sender.setPort(port);// www . java 2 s. co m SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("from@com.springsource.insight.plugin.mail"); message.setTo("to@com.springsource.insight.plugin.mail"); message.setCc("cc@com.springsource.insight.plugin.mail"); message.setBcc("bcc@com.springsource.insight.plugin.mail"); Date now = new Date(System.currentTimeMillis()); message.setSentDate(now); message.setSubject(now.toString()); message.setText("Test at " + now.toString()); sender.send(message); Operation op = getLastEntered(); assertNotNull("No operation extracted", op); assertEquals("Mismatched operation type", MailDefinitions.SEND_OPERATION, op.getType()); assertEquals("Mismatched protocol", sender.getProtocol(), op.get(MailDefinitions.SEND_PROTOCOL, String.class)); assertEquals("Mismatched host", sender.getHost(), op.get(MailDefinitions.SEND_HOST, String.class)); if (port == -1) { assertEquals("Mismatched default port", 25, op.getInt(MailDefinitions.SEND_PORT, (-1))); } else { assertEquals("Mismatched send port", sender.getPort(), op.getInt(MailDefinitions.SEND_PORT, (-1))); } if (getAspect().collectExtraInformation()) { assertAddresses(op, MailDefinitions.SEND_SENDERS, 1); assertAddresses(op, MailDefinitions.SEND_RECIPS, 3); OperationMap details = op.get(MailDefinitions.SEND_DETAILS, OperationMap.class); assertNotNull("No details extracted", details); assertEquals("Mismatched subject", message.getSubject(), details.get(MailDefinitions.SEND_SUBJECT, String.class)); } }