1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.mail;
  17. import org.springframework.util.StringUtils;
  18. /**
  19. * Encapsulates properties of a simple mail such as from, to, cc,
  20. * subject, text. To be sent with a MailSender implementation.
  21. *
  22. * <p>Consider JavaMailSender and JavaMail MimeMessages for creating
  23. * more sophisticated messages, for example with attachments, special
  24. * character encodings, or personal names that accompany mail addresses.
  25. *
  26. * @author Dmitriy Kopylenko
  27. * @author Juergen Hoeller
  28. * @since 10.09.2003
  29. * @version $Id: SimpleMailMessage.java,v 1.7 2004/03/18 02:46:05 trisberg Exp $
  30. * @see MailSender
  31. * @see org.springframework.mail.javamail.JavaMailSender
  32. * @see org.springframework.mail.javamail.MimeMessagePreparator
  33. * @see org.springframework.mail.javamail.MimeMessageHelper
  34. */
  35. public class SimpleMailMessage {
  36. private String from;
  37. private String[] to;
  38. private String[] cc;
  39. private String[] bcc;
  40. private String subject;
  41. private String text;
  42. /**
  43. * Create new SimpleMailMessage.
  44. */
  45. public SimpleMailMessage() {
  46. }
  47. /**
  48. * Copy constructor.
  49. */
  50. public SimpleMailMessage(SimpleMailMessage original) {
  51. this.from = original.getFrom();
  52. if (original.getTo() != null) {
  53. this.to = new String[original.getTo().length];
  54. System.arraycopy(original.getTo(), 0, this.to, 0, original.getTo().length);
  55. }
  56. if (original.getCc() != null) {
  57. this.cc = new String[original.getCc().length];
  58. System.arraycopy(original.getCc(), 0, this.cc, 0, original.getCc().length);
  59. }
  60. if (original.getBcc() != null) {
  61. this.bcc = new String[original.getBcc().length];
  62. System.arraycopy(original.getBcc(), 0, this.bcc, 0, original.getBcc().length);
  63. }
  64. this.subject = original.getSubject();
  65. this.text = original.getText();
  66. }
  67. public void setFrom(String from) {
  68. this.from = from;
  69. }
  70. public String getFrom() {
  71. return this.from;
  72. }
  73. public void setTo(String to) {
  74. this.to = new String[] {to};
  75. }
  76. public void setTo(String[] to) {
  77. this.to = to;
  78. }
  79. public String[] getTo() {
  80. return this.to;
  81. }
  82. public void setCc(String cc) {
  83. this.cc = new String[] {cc};
  84. }
  85. public void setCc(String[] cc) {
  86. this.cc = cc;
  87. }
  88. public String[] getCc() {
  89. return cc;
  90. }
  91. public void setBcc(String bcc) {
  92. this.bcc = new String[] {bcc};
  93. }
  94. public void setBcc(String[] bcc) {
  95. this.bcc = bcc;
  96. }
  97. public String[] getBcc() {
  98. return bcc;
  99. }
  100. public void setSubject(String subject) {
  101. this.subject = subject;
  102. }
  103. public String getSubject() {
  104. return this.subject;
  105. }
  106. public void setText(String text) {
  107. this.text = text;
  108. }
  109. public String getText() {
  110. return this.text;
  111. }
  112. public String toString() {
  113. StringBuffer sb = new StringBuffer("SimpleMailMessage: ");
  114. sb.append("from: " + this.getFrom()+ "; ");
  115. sb.append("to: " + StringUtils.arrayToCommaDelimitedString(this.getTo()) + "; ");
  116. sb.append("cc: " + StringUtils.arrayToCommaDelimitedString(this.getCc()) + "; ");
  117. sb.append("bcc: " + StringUtils.arrayToCommaDelimitedString(this.getBcc()) + "; ");
  118. sb.append("subject: " + this.getSubject()+ "; ");
  119. sb.append("text: " + this.getText());
  120. return sb.toString();
  121. }
  122. }