SimpleMailMessage.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 4k
Category:

Java Develop

Development Platform:

Java

  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 java.io.Serializable;
  18. import java.util.Date;
  19. import org.springframework.util.StringUtils;
  20. /**
  21.  * Encapsulates properties of a simple mail such as from, to, cc,
  22.  * subject, text. To be sent with a MailSender implementation.
  23.  *
  24.  * <p>Consider JavaMailSender and JavaMail MimeMessages for creating
  25.  * more sophisticated messages, for example with attachments, special
  26.  * character encodings, or personal names that accompany mail addresses.
  27.  *
  28.  * @author Dmitriy Kopylenko
  29.  * @author Juergen Hoeller
  30.  * @since 10.09.2003
  31.  * @see MailSender
  32.  * @see org.springframework.mail.javamail.JavaMailSender
  33.  * @see org.springframework.mail.javamail.MimeMessagePreparator
  34.  * @see org.springframework.mail.javamail.MimeMessageHelper
  35.  */
  36. public class SimpleMailMessage implements Serializable {
  37. private String from;
  38. private String replyTo;
  39. private String[] to;
  40. private String[] cc;
  41. private String[] bcc;
  42. private Date sentDate;
  43. private String subject;
  44. private String text;
  45. /**
  46.  * Create new SimpleMailMessage.
  47.  */
  48. public SimpleMailMessage() {
  49. }
  50. /**
  51.  * Copy constructor.
  52.  */
  53. public SimpleMailMessage(SimpleMailMessage original) {
  54. this.from = original.getFrom();
  55. this.replyTo = original.getReplyTo();
  56. if (original.getTo() != null) {
  57. this.to = new String[original.getTo().length];
  58. System.arraycopy(original.getTo(), 0, this.to, 0, original.getTo().length);
  59. }
  60. if (original.getCc() != null) {
  61. this.cc = new String[original.getCc().length];
  62. System.arraycopy(original.getCc(), 0, this.cc, 0, original.getCc().length);
  63. }
  64. if (original.getBcc() != null) {
  65. this.bcc = new String[original.getBcc().length];
  66. System.arraycopy(original.getBcc(), 0, this.bcc, 0, original.getBcc().length);
  67. }
  68. this.sentDate = original.getSentDate();
  69. this.subject = original.getSubject();
  70. this.text = original.getText();
  71. }
  72. public void setFrom(String from) {
  73. this.from = from;
  74. }
  75. public String getFrom() {
  76. return this.from;
  77. }
  78. public void setReplyTo(String replyTo) {
  79. this.replyTo = replyTo;
  80. }
  81. public String getReplyTo() {
  82. return replyTo;
  83. }
  84. public void setTo(String to) {
  85. this.to = new String[] {to};
  86. }
  87. public void setTo(String[] to) {
  88. this.to = to;
  89. }
  90. public String[] getTo() {
  91. return this.to;
  92. }
  93. public void setCc(String cc) {
  94. this.cc = new String[] {cc};
  95. }
  96. public void setCc(String[] cc) {
  97. this.cc = cc;
  98. }
  99. public String[] getCc() {
  100. return cc;
  101. }
  102. public void setBcc(String bcc) {
  103. this.bcc = new String[] {bcc};
  104. }
  105. public void setBcc(String[] bcc) {
  106. this.bcc = bcc;
  107. }
  108. public String[] getBcc() {
  109. return bcc;
  110. }
  111. public void setSentDate(Date sentDate) {
  112. this.sentDate = sentDate;
  113. }
  114. public Date getSentDate() {
  115. return sentDate;
  116. }
  117. public void setSubject(String subject) {
  118. this.subject = subject;
  119. }
  120. public String getSubject() {
  121. return this.subject;
  122. }
  123. public void setText(String text) {
  124. this.text = text;
  125. }
  126. public String getText() {
  127. return this.text;
  128. }
  129. public String toString() {
  130. StringBuffer sb = new StringBuffer("SimpleMailMessage: ");
  131. sb.append("from=").append(this.from).append("; ");
  132. sb.append("replyTo=").append(this.replyTo).append("; ");
  133. sb.append("to=").append( StringUtils.arrayToCommaDelimitedString(this.to)).append("; ");
  134. sb.append("cc=").append(StringUtils.arrayToCommaDelimitedString(this.cc)).append("; ");
  135. sb.append("bcc=").append(StringUtils.arrayToCommaDelimitedString(this.bcc)).append("; ");
  136. sb.append("sentDate=").append(this.sentDate).append("; ");
  137. sb.append("subject=").append(this.subject).append("; ");
  138. sb.append("text=").append(this.text);
  139. return sb.toString();
  140. }
  141. }