85 |
brianR |
1 |
/*
|
|
|
2 |
* Copyright 2012 Brian Rosenberger (Brutex Network)
|
|
|
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 |
|
|
|
17 |
package net.brutex.xservices.ws.impl;
|
|
|
18 |
|
|
|
19 |
import javax.jws.WebService;
|
|
|
20 |
|
|
|
21 |
import net.brutex.xservices.types.HostConnection;
|
|
|
22 |
import net.brutex.xservices.types.MailMimeType;
|
|
|
23 |
import net.brutex.xservices.types.ReturnCode;
|
|
|
24 |
import net.brutex.xservices.types.ant.FileSetResource;
|
|
|
25 |
import net.brutex.xservices.util.BrutexNamespaces;
|
|
|
26 |
import net.brutex.xservices.util.RunTask;
|
|
|
27 |
import net.brutex.xservices.ws.MailService;
|
|
|
28 |
|
|
|
29 |
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Implements MailService
|
|
|
33 |
*
|
|
|
34 |
* @author Brian Rosenberger, bru@brutex.de
|
|
|
35 |
*/
|
|
|
36 |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES,
|
|
|
37 |
endpointInterface = "net.brutex.xservices.ws.MailService",
|
|
|
38 |
serviceName = "MailService")
|
|
|
39 |
public class MailServiceImpl implements MailService {
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
public ReturnCode sendMailSimple(HostConnection mailhost, String from,
|
|
|
43 |
String tolist, String subject, String message) {
|
|
|
44 |
return sendMail(from, from, tolist, "", "", subject, message,
|
|
|
45 |
"text/plain", null, mailhost.hostname, mailhost.port,
|
|
|
46 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
|
|
|
50 |
String from, String tolist, String subject, String message,
|
|
|
51 |
FileSetResource res) {
|
|
|
52 |
return sendMail(from, from, tolist, "", "", subject, message,
|
|
|
53 |
"text/plain", res, mailhost.hostname, mailhost.port,
|
|
|
54 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public ReturnCode sendMail(HostConnection mailhost, String from,
|
|
|
58 |
String tolist, String cclist, String bcclist, String subject,
|
|
|
59 |
MailMimeType mimetype, String charset, String message,
|
|
|
60 |
FileSetResource res, boolean ssl, boolean tls) {
|
|
|
61 |
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
|
|
|
62 |
mimetype.value(), res, mailhost.hostname, mailhost.port,
|
|
|
63 |
mailhost.user, mailhost.password, charset, tls, ssl);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private ReturnCode sendMail(String from, String replyto, String tolist,
|
|
|
67 |
String cclist, String bcclist, String subject, String message,
|
|
|
68 |
String messagemimetype, FileSetResource attachments,
|
|
|
69 |
String mailhost, int mailport, String user, String password,
|
|
|
70 |
String charset, boolean tls, boolean ssl) {
|
|
|
71 |
EmailTask mail = new EmailTask();
|
|
|
72 |
mail.setTaskName("Mail");
|
|
|
73 |
RunTask runner = new RunTask(mail);
|
|
|
74 |
mail.setFrom(from);
|
|
|
75 |
mail.setReplyTo(replyto);
|
|
|
76 |
mail.setToList(tolist);
|
|
|
77 |
mail.setCcList(cclist);
|
|
|
78 |
mail.setBccList(bcclist);
|
|
|
79 |
mail.setSubject(subject);
|
|
|
80 |
mail.setMessage(message);
|
182 |
brianR |
81 |
//mail.setMessageMimeType(messagemimetype);
|
85 |
brianR |
82 |
if (attachments != null) {
|
|
|
83 |
mail.addFileset(attachments.getAntResource(mail.getProject()));
|
|
|
84 |
}
|
|
|
85 |
mail.setMailhost(mailhost);
|
|
|
86 |
mail.setMailport(mailport);
|
|
|
87 |
mail.setUser(user);
|
|
|
88 |
mail.setPassword(password);
|
|
|
89 |
mail.setCharset(charset);
|
|
|
90 |
mail.setSSL(ssl);
|
|
|
91 |
mail.setEnableStartTLS(tls);
|
|
|
92 |
return runner.postTask();
|
|
|
93 |
}
|
|
|
94 |
}
|