1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.email; |
12 | |
|
13 | |
import org.mule.umo.UMOComponent; |
14 | |
import org.mule.umo.lifecycle.InitialisationException; |
15 | |
import org.mule.umo.endpoint.UMOEndpoint; |
16 | |
import org.mule.umo.provider.UMOMessageReceiver; |
17 | |
|
18 | |
import java.util.Properties; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public class SmtpConnector extends AbstractMailConnector |
25 | |
{ |
26 | |
public static final String DEFAULT_SMTP_HOST = "localhost"; |
27 | |
public static final int DEFAULT_SMTP_PORT = 25; |
28 | |
public static final String DEFAULT_CONTENT_TYPE = "text/plain"; |
29 | |
|
30 | 0 | private String host = DEFAULT_SMTP_HOST; |
31 | 0 | private int port = DEFAULT_SMTP_PORT; |
32 | |
private String username; |
33 | |
private String password; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
private String bcc; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
private String cc; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
private String replyTo; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | private String defaultSubject = "[No Subject]"; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
private String from; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 0 | private Properties customHeaders = new Properties(); |
64 | |
|
65 | 0 | private String contentType = DEFAULT_CONTENT_TYPE; |
66 | |
|
67 | |
|
68 | |
public SmtpConnector() |
69 | |
{ |
70 | 0 | this(DEFAULT_SMTP_PORT); |
71 | 0 | } |
72 | |
|
73 | |
SmtpConnector(int defaultPort) |
74 | |
{ |
75 | 0 | super(defaultPort, null); |
76 | 0 | } |
77 | |
|
78 | |
public String getProtocol() |
79 | |
{ |
80 | 0 | return "smtp"; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
protected void doInitialise() throws InitialisationException |
85 | |
{ |
86 | |
|
87 | |
|
88 | 0 | if(getFromAddress()==null && getUsername()!=null && getUsername().indexOf('@') > -1) |
89 | |
{ |
90 | 0 | setFromAddress(getUsername()); |
91 | |
} |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception |
101 | |
{ |
102 | 0 | throw new UnsupportedOperationException("Listeners cannot be registered on a SMTP endpoint"); |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public String getFromAddress() |
109 | |
{ |
110 | 0 | return from; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public String getBccAddresses() |
117 | |
{ |
118 | 0 | return bcc; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public String getCcAddresses() |
125 | |
{ |
126 | 0 | return cc; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public String getSubject() |
133 | |
{ |
134 | 0 | return defaultSubject; |
135 | |
} |
136 | |
|
137 | |
public void setBccAddresses(String string) |
138 | |
{ |
139 | 0 | bcc = string; |
140 | 0 | } |
141 | |
|
142 | |
public void setCcAddresses(String string) |
143 | |
{ |
144 | 0 | cc = string; |
145 | 0 | } |
146 | |
|
147 | |
public void setSubject(String string) |
148 | |
{ |
149 | 0 | defaultSubject = string; |
150 | 0 | } |
151 | |
|
152 | |
public void setFromAddress(String string) |
153 | |
{ |
154 | 0 | from = string; |
155 | 0 | } |
156 | |
|
157 | |
public String getReplyToAddresses() |
158 | |
{ |
159 | 0 | return replyTo; |
160 | |
} |
161 | |
|
162 | |
public void setReplyToAddresses(String replyTo) |
163 | |
{ |
164 | 0 | this.replyTo = replyTo; |
165 | 0 | } |
166 | |
|
167 | |
public Properties getCustomHeaders() |
168 | |
{ |
169 | 0 | return customHeaders; |
170 | |
} |
171 | |
|
172 | |
public void setCustomHeaders(Properties customHeaders) |
173 | |
{ |
174 | 0 | this.customHeaders = customHeaders; |
175 | 0 | } |
176 | |
|
177 | |
public String getContentType() |
178 | |
{ |
179 | 0 | return contentType; |
180 | |
} |
181 | |
|
182 | |
public void setContentType(String contentType) |
183 | |
{ |
184 | 0 | this.contentType = contentType; |
185 | 0 | } |
186 | |
|
187 | |
public int getDefaultPort() |
188 | |
{ |
189 | 0 | return DEFAULT_SMTP_PORT; |
190 | |
} |
191 | |
|
192 | |
public String getHost() |
193 | |
{ |
194 | 0 | return host; |
195 | |
} |
196 | |
|
197 | |
public void setHost(String host) |
198 | |
{ |
199 | 0 | this.host = host; |
200 | 0 | } |
201 | |
|
202 | |
public String getPassword() |
203 | |
{ |
204 | 0 | return password; |
205 | |
} |
206 | |
|
207 | |
public void setPassword(String password) |
208 | |
{ |
209 | 0 | this.password = password; |
210 | 0 | } |
211 | |
|
212 | |
public int getPort() |
213 | |
{ |
214 | 0 | return port; |
215 | |
} |
216 | |
|
217 | |
public void setPort(int port) |
218 | |
{ |
219 | 0 | this.port = port; |
220 | 0 | } |
221 | |
|
222 | |
public String getUsername() |
223 | |
{ |
224 | 0 | return username; |
225 | |
} |
226 | |
|
227 | |
public void setUsername(String username) |
228 | |
{ |
229 | 0 | this.username = username; |
230 | 0 | } |
231 | |
|
232 | |
} |