View Javadoc

1   /*
2    * $Id: SmtpConnector.java 11110 2008-02-28 13:55:36Z acooke $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.email;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.service.Service;
15  import org.mule.api.transport.MessageReceiver;
16  
17  import java.util.Properties;
18  
19  /**
20   * <code>SmtpConnector</code> is used to connect to and send data to an SMTP mail
21   * server
22   */
23  public class SmtpConnector extends AbstractMailConnector
24  {
25  
26      public static final String SMTP = "smtp";
27      public static final String DEFAULT_SMTP_HOST = "localhost";
28      public static final int DEFAULT_SMTP_PORT = 25;
29      public static final String DEFAULT_CONTENT_TYPE = "text/plain";
30  
31      /**
32       * Holds value of bcc addresses.
33       */
34      private String bcc;
35  
36      /**
37       * Holds value of cc addresses.
38       */
39      private String cc;
40  
41      /**
42       * Holds value of replyTo addresses.
43       */
44      private String replyTo;
45  
46      /**
47       * Holds value of default subject
48       */
49      private String defaultSubject = "[No Subject]";
50  
51      /**
52       * Holds value of the from address.
53       */
54      private String from;
55  
56      /**
57       * Any custom headers to be set on messages sent using this connector
58       */
59      private Properties customHeaders = new Properties();
60  
61      private String contentType = DEFAULT_CONTENT_TYPE;
62  
63      
64      public SmtpConnector()
65      {
66          this(DEFAULT_SMTP_PORT);
67      }
68      
69      SmtpConnector(int defaultPort)
70      {
71          super(defaultPort, null);
72      }
73      
74      public String getProtocol()
75      {
76          return "smtp";
77      }
78  
79      /*
80       * (non-Javadoc)
81       * 
82       * @see org.mule.transport.UMOConnector#registerListener(javax.jms.MessageListener,
83       *      java.lang.String)
84       */
85      public MessageReceiver createReceiver(Service service, InboundEndpoint endpoint) throws Exception
86      {
87          throw new UnsupportedOperationException("Listeners cannot be registered on a SMTP endpoint");
88      }
89  
90      /**
91       * @return The default from address to use
92       */
93      public String getFromAddress()
94      {
95          return from;
96      }
97  
98      /**
99       * @return the default comma separated list of BCC addresses to use
100      */
101     public String getBccAddresses()
102     {
103         return bcc;
104     }
105 
106     /**
107      * @return the default comma separated list of CC addresses to use
108      */
109     public String getCcAddresses()
110     {
111         return cc;
112     }
113 
114     /**
115      * @return the default message subject to use
116      */
117     public String getSubject()
118     {
119         return defaultSubject;
120     }
121 
122     public void setBccAddresses(String string)
123     {
124         bcc = string;
125     }
126 
127     public void setCcAddresses(String string)
128     {
129         cc = string;
130     }
131 
132     public void setSubject(String string)
133     {
134         defaultSubject = string;
135     }
136 
137     public void setFromAddress(String string)
138     {
139         from = string;
140     }
141 
142     public String getReplyToAddresses()
143     {
144         return replyTo;
145     }
146 
147     public void setReplyToAddresses(String replyTo)
148     {
149         this.replyTo = replyTo;
150     }
151 
152     public Properties getCustomHeaders()
153     {
154         return customHeaders;
155     }
156 
157     public void setCustomHeaders(Properties customHeaders)
158     {
159         this.customHeaders = customHeaders;
160     }
161 
162     public String getContentType()
163     {
164         return contentType;
165     }
166 
167     public void setContentType(String contentType)
168     {
169         this.contentType = contentType;
170     }
171 
172     public int getDefaultPort()
173     {
174         return DEFAULT_SMTP_PORT;
175     }
176 
177 }