Package org.springframework.mail

Examples of org.springframework.mail.SimpleMailMessage


public abstract class SimpleMailSender {

    protected abstract MailSender getMailSender();
   
    public void sendMessage(String to, String text) {
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setTo(to);
        msg.setSubject("Test Message");
        msg.setFrom("test@apress.com");
        msg.setText(text);
       
        MailSender sender = getMailSender();
        sender.send(msg);
    }
View Full Code Here


    sender.setHost("host");
    sender.setPort(30);
    sender.setUsername("username");
    sender.setPassword("password");

    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("me@mail.org");
    simpleMessage.setReplyTo("reply@mail.org");
    simpleMessage.setTo("you@mail.org");
    simpleMessage.setCc(new String[] {"he@mail.org", "she@mail.org"});
    simpleMessage.setBcc(new String[] {"us@mail.org", "them@mail.org"});
    Date sentDate = new Date(2004, 1, 1);
    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());
View Full Code Here

    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPassword("password");

    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("he@mail.org");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("she@mail.org");
    sender.send(new SimpleMailMessage[] {simpleMessage1, simpleMessage2});

    assertEquals(sender.transport.getConnectedHost(), "host");
    assertEquals(sender.transport.getConnectedUsername(), "username");
    assertEquals(sender.transport.getConnectedPassword(), "password");
View Full Code Here

    assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
  }

  public void testJavaMailSenderWithParseExceptionOnSimpleMessage() {
    MockJavaMailSender sender = new MockJavaMailSender();
    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("");
    try {
      sender.send(simpleMessage);
    }
    catch (MailParseException ex) {
      // expected
View Full Code Here

  public void testFailedMailServerConnect() throws Exception {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost(null);
    sender.setUsername("username");
    sender.setPassword("password");
    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    try {
      sender.send(simpleMessage1);
      fail("Should have thrown MailSendException");
    }
    catch (MailSendException ex) {
View Full Code Here

    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPassword("password");

    SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
    simpleMessage1.setTo("he@mail.org");
    simpleMessage1.setSubject("fail");
    SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
    simpleMessage2.setTo("she@mail.org");

    try {
      sender.send(new SimpleMailMessage[] {simpleMessage1, simpleMessage2});
    }
    catch (MailSendException ex) {
View Full Code Here

      try {
        String name = newEvent.get("name").toString();
        String value = newEvent.get("value").toString();
        String colo = newEvent.get("colo").toString();

        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);

        msg.setTo(this.recipient);

        logger.info(
            " event triggered - type " + type + " - " + colo + " - " + name + " - " + value);
        msg.setText(
            " event triggered - type " + type + " - " + colo + " - " + name + " - " + value);

        // this.mailSender.send(msg);

      } catch (Exception e) {
View Full Code Here

        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) {
View Full Code Here

    }

    @Override
    public void run() {
      System.out.println("开始发送邮件");
      SimpleMailMessage mail = new SimpleMailMessage();
      // 注意SimpleMailMessage只能用来发送text格式的邮件

      try {
        mail.setTo(toUser);// 接受者
        mail.setFrom(fromUser);// 发送者,这里还可以另起Email别名,不用和xml里的username一致
        mail.setSubject(subject);// 主题
        mail.setText(text);// 邮件内容
        javaMailSender.send(mail);
      } catch (Exception e) {
        System.out.println("发送邮件异常!");
        e.printStackTrace();
      }
View Full Code Here

  }

  public void send(SimpleMailMessage[] simpleMessages) throws MailException {
    List mimeMessages = new ArrayList(simpleMessages.length);
    for (int i = 0; i < simpleMessages.length; i++) {
      SimpleMailMessage simpleMessage = simpleMessages[i];
      MimeMailMessage message = new MimeMailMessage(createMimeMessage());
      simpleMessage.copyTo(message);
      mimeMessages.add(message.getMimeMessage());
    }
    doSend((MimeMessage[]) mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages);
  }
View Full Code Here

TOP

Related Classes of org.springframework.mail.SimpleMailMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.