Java Code Examples for org.springframework.mail.SimpleMailMessage#setSentDate()
The following examples show how to use
org.springframework.mail.SimpleMailMessage#setSentDate() .
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: SpringMailSenderBackend.java From haven-platform with Apache License 2.0 | 7 votes |
@Override public void send(MailMessage message) throws MailSenderException { SimpleMailMessage smm = new SimpleMailMessage(); MailBody body = message.getBody(); smm.setText(MailUtils.toPlainText(body)); MailHead head = message.getHead(); smm.setFrom(head.getFrom()); smm.setReplyTo(head.getReplyTo()); smm.setSubject(head.getSubject()); smm.setTo(asArray(head.getTo())); smm.setCc(asArray(head.getCc())); smm.setBcc(asArray(head.getBcc())); smm.setSentDate(head.getSentDate()); LOG.info("message to send {}", smm); mailSender.send(smm); }
Example 2
Source File: AbstarctMailSender.java From beihu-boot with Apache License 2.0 | 6 votes |
private void doSendMail(String email, String message, String detail) { if (javaMailSender == null || StringUtils.isBlank(sendFrom) || StringUtils.isBlank(email) || StringUtils.isBlank(prefix)) { logger.error("=====================【邮件服务异常】初始化失败! ======================="); return; } String[] tos = StringUtils.split(email, ","); if (tos.length < 1) { logger.warn("=====================【邮件服务异常】无发送列表! ======================="); return; } try { SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom(sendFrom); simpleMailMessage.setTo(tos); simpleMailMessage.setSubject(prefix + " : " + message); simpleMailMessage.setText(detail); simpleMailMessage.setSentDate(new Date()); javaMailSender.send(simpleMailMessage);//发送邮件 logger.info("==========================邮件发送成功=========================="); } catch (Exception e) { logger.error("==========================邮件发送失败==========================", e); } }
Example 3
Source File: MailMessageNotifier.java From super-cloudops with Apache License 2.0 | 5 votes |
/** * Send mail messages. * * @param simpleMessages */ @Override public void send(GenericNotifyMessage msg) { String mailMsgType = msg.getParameterAsString(KEY_MAILMSG_TYPE, "simple"); switch (mailMsgType) { case KEY_MAILMSG_VALUE_SIMPLE: SimpleMailMessage simpleMsg = new SimpleMailMessage(); // Add "<>" symbol to send out? /* * Preset from account, otherwise it would be wrong: 501 mail from * address must be same as authorization user. */ simpleMsg.setFrom(config.getUsername() + "<" + config.getUsername() + ">"); simpleMsg.setTo(msg.getToObjects().stream().map(to -> to = to + "<" + to + ">").collect(toList()).toArray(new String[]{})); simpleMsg.setSubject(msg.getParameterAsString(KEY_MAILMSG_SUBJECT, "Super Devops Messages")); simpleMsg.setSentDate(msg.getParameter(KEY_MSG_SENDDATE, new Date())); simpleMsg.setBcc(safeList(msg.getParameter(KEY_MAILMSG_BCC)).toArray(new String[]{})); simpleMsg.setCc(safeList(msg.getParameter(KEY_MAILMSG_CC)).toArray(new String[]{})); simpleMsg.setReplyTo(msg.getParameter(KEY_MAILMSG_REPLYTO)); simpleMsg.setText(config.getResolvedMessage(msg.getTemplateKey(), msg.getParameters())); mailSender.send(simpleMsg); break; case KEY_MAILMSG_VALUE_MIME: // TODO implements!!! log.warn("No implements MimeMailMessage!!!"); break; default: throw new UnsupportedOperationException(format("No supported mail message type of %s", mailMsgType)); } }
Example 4
Source File: JavaMailSenderTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost("host"); sender.setPort(30); sender.setUsername("username"); sender.setPassword("password"); SimpleMailMessage simpleMessage = new SimpleMailMessage(); simpleMessage.setFrom("[email protected]"); simpleMessage.setReplyTo("[email protected]"); simpleMessage.setTo("[email protected]"); simpleMessage.setCc("[email protected]", "[email protected]"); simpleMessage.setBcc("[email protected]", "[email protected]"); Date sentDate = new GregorianCalendar(2004, 1, 1).getTime(); simpleMessage.setSentDate(sentDate); simpleMessage.setSubject("my subject"); simpleMessage.setText("my text"); sender.send(simpleMessage); assertEquals("host", sender.transport.getConnectedHost()); assertEquals(30, sender.transport.getConnectedPort()); assertEquals("username", sender.transport.getConnectedUsername()); assertEquals("password", sender.transport.getConnectedPassword()); assertTrue(sender.transport.isCloseCalled()); assertEquals(1, sender.transport.getSentMessages().size()); MimeMessage sentMessage = sender.transport.getSentMessage(0); List<Address> froms = Arrays.asList(sentMessage.getFrom()); assertEquals(1, froms.size()); assertEquals("[email protected]", ((InternetAddress) froms.get(0)).getAddress()); List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo()); assertEquals("[email protected]", ((InternetAddress) replyTos.get(0)).getAddress()); List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO)); assertEquals(1, tos.size()); assertEquals("[email protected]", ((InternetAddress) tos.get(0)).getAddress()); List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC)); assertEquals(2, ccs.size()); assertEquals("[email protected]", ((InternetAddress) ccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) ccs.get(1)).getAddress()); List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC)); assertEquals(2, bccs.size()); assertEquals("[email protected]", ((InternetAddress) bccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) bccs.get(1)).getAddress()); assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime()); assertEquals("my subject", sentMessage.getSubject()); assertEquals("my text", sentMessage.getContent()); }
Example 5
Source File: JavaMailSenderTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost("host"); sender.setPort(30); sender.setUsername("username"); sender.setPassword("password"); SimpleMailMessage simpleMessage = new SimpleMailMessage(); simpleMessage.setFrom("[email protected]"); simpleMessage.setReplyTo("[email protected]"); simpleMessage.setTo("[email protected]"); simpleMessage.setCc("[email protected]", "[email protected]"); simpleMessage.setBcc("[email protected]", "[email protected]"); Date sentDate = new GregorianCalendar(2004, 1, 1).getTime(); simpleMessage.setSentDate(sentDate); simpleMessage.setSubject("my subject"); simpleMessage.setText("my text"); sender.send(simpleMessage); assertEquals("host", sender.transport.getConnectedHost()); assertEquals(30, sender.transport.getConnectedPort()); assertEquals("username", sender.transport.getConnectedUsername()); assertEquals("password", sender.transport.getConnectedPassword()); assertTrue(sender.transport.isCloseCalled()); assertEquals(1, sender.transport.getSentMessages().size()); MimeMessage sentMessage = sender.transport.getSentMessage(0); List<Address> froms = Arrays.asList(sentMessage.getFrom()); assertEquals(1, froms.size()); assertEquals("[email protected]", ((InternetAddress) froms.get(0)).getAddress()); List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo()); assertEquals("[email protected]", ((InternetAddress) replyTos.get(0)).getAddress()); List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO)); assertEquals(1, tos.size()); assertEquals("[email protected]", ((InternetAddress) tos.get(0)).getAddress()); List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC)); assertEquals(2, ccs.size()); assertEquals("[email protected]", ((InternetAddress) ccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) ccs.get(1)).getAddress()); List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC)); assertEquals(2, bccs.size()); assertEquals("[email protected]", ((InternetAddress) bccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) bccs.get(1)).getAddress()); assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime()); assertEquals("my subject", sentMessage.getSubject()); assertEquals("my text", sentMessage.getContent()); }
Example 6
Source File: JavaMailSenderTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost("host"); sender.setPort(30); sender.setUsername("username"); sender.setPassword("password"); SimpleMailMessage simpleMessage = new SimpleMailMessage(); simpleMessage.setFrom("[email protected]"); simpleMessage.setReplyTo("[email protected]"); simpleMessage.setTo("[email protected]"); simpleMessage.setCc(new String[] {"[email protected]", "[email protected]"}); simpleMessage.setBcc(new String[] {"[email protected]", "[email protected]"}); Date sentDate = new GregorianCalendar(2004, 1, 1).getTime(); simpleMessage.setSentDate(sentDate); simpleMessage.setSubject("my subject"); simpleMessage.setText("my text"); sender.send(simpleMessage); assertEquals("host", sender.transport.getConnectedHost()); assertEquals(30, sender.transport.getConnectedPort()); assertEquals("username", sender.transport.getConnectedUsername()); assertEquals("password", sender.transport.getConnectedPassword()); assertTrue(sender.transport.isCloseCalled()); assertEquals(1, sender.transport.getSentMessages().size()); MimeMessage sentMessage = sender.transport.getSentMessage(0); List<Address> froms = Arrays.asList(sentMessage.getFrom()); assertEquals(1, froms.size()); assertEquals("[email protected]", ((InternetAddress) froms.get(0)).getAddress()); List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo()); assertEquals("[email protected]", ((InternetAddress) replyTos.get(0)).getAddress()); List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO)); assertEquals(1, tos.size()); assertEquals("[email protected]", ((InternetAddress) tos.get(0)).getAddress()); List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC)); assertEquals(2, ccs.size()); assertEquals("[email protected]", ((InternetAddress) ccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) ccs.get(1)).getAddress()); List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC)); assertEquals(2, bccs.size()); assertEquals("[email protected]", ((InternetAddress) bccs.get(0)).getAddress()); assertEquals("[email protected]", ((InternetAddress) bccs.get(1)).getAddress()); assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime()); assertEquals("my subject", sentMessage.getSubject()); assertEquals("my text", sentMessage.getContent()); }