Subversion Repositories XServices

Rev

Rev 85 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 85 Rev 182
1
/*
1
/*
2
 *   Copyright 2012 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2012 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with 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
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.ws.impl;
17
package net.brutex.xservices.ws.impl;
18
 
18
 
19
import javax.jws.WebService;
19
import javax.jws.WebService;
20
 
20
 
21
import net.brutex.xservices.types.HostConnection;
21
import net.brutex.xservices.types.HostConnection;
22
import net.brutex.xservices.types.MailMimeType;
22
import net.brutex.xservices.types.MailMimeType;
23
import net.brutex.xservices.types.ReturnCode;
23
import net.brutex.xservices.types.ReturnCode;
24
import net.brutex.xservices.types.ant.FileSetResource;
24
import net.brutex.xservices.types.ant.FileSetResource;
25
import net.brutex.xservices.util.BrutexNamespaces;
25
import net.brutex.xservices.util.BrutexNamespaces;
26
import net.brutex.xservices.util.RunTask;
26
import net.brutex.xservices.util.RunTask;
27
import net.brutex.xservices.ws.MailService;
27
import net.brutex.xservices.ws.MailService;
28
 
28
 
29
import org.apache.tools.ant.taskdefs.email.EmailTask;
29
import org.apache.tools.ant.taskdefs.email.EmailTask;
30
 
30
 
31
/**
31
/**
32
 * Implements MailService
32
 * Implements MailService
33
 * 
33
 * 
34
 * @author Brian Rosenberger, bru@brutex.de
34
 * @author Brian Rosenberger, bru@brutex.de
35
 */
35
 */
36
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, 
36
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, 
37
			endpointInterface = "net.brutex.xservices.ws.MailService", 
37
			endpointInterface = "net.brutex.xservices.ws.MailService", 
38
			serviceName = "MailService")
38
			serviceName = "MailService")
39
public class MailServiceImpl implements MailService {
39
public class MailServiceImpl implements MailService {
40
 
40
 
41
 
41
 
42
	public ReturnCode sendMailSimple(HostConnection mailhost, String from,
42
	public ReturnCode sendMailSimple(HostConnection mailhost, String from,
43
			String tolist, String subject, String message) {
43
			String tolist, String subject, String message) {
44
		return sendMail(from, from, tolist, "", "", subject, message,
44
		return sendMail(from, from, tolist, "", "", subject, message,
45
				"text/plain", null, mailhost.hostname, mailhost.port,
45
				"text/plain", null, mailhost.hostname, mailhost.port,
46
				mailhost.user, mailhost.password, "utf-8", false, false);
46
				mailhost.user, mailhost.password, "utf-8", false, false);
47
	}
47
	}
48
 
48
 
49
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
49
	public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
50
			String from, String tolist, String subject, String message,
50
			String from, String tolist, String subject, String message,
51
			FileSetResource res) {
51
			FileSetResource res) {
52
		return sendMail(from, from, tolist, "", "", subject, message,
52
		return sendMail(from, from, tolist, "", "", subject, message,
53
				"text/plain", res, mailhost.hostname, mailhost.port,
53
				"text/plain", res, mailhost.hostname, mailhost.port,
54
				mailhost.user, mailhost.password, "utf-8", false, false);
54
				mailhost.user, mailhost.password, "utf-8", false, false);
55
	}
55
	}
56
 
56
 
57
	public ReturnCode sendMail(HostConnection mailhost, String from,
57
	public ReturnCode sendMail(HostConnection mailhost, String from,
58
			String tolist, String cclist, String bcclist, String subject,
58
			String tolist, String cclist, String bcclist, String subject,
59
			MailMimeType mimetype, String charset, String message,
59
			MailMimeType mimetype, String charset, String message,
60
			FileSetResource res, boolean ssl, boolean tls) {
60
			FileSetResource res, boolean ssl, boolean tls) {
61
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
61
		return sendMail(from, from, tolist, cclist, bcclist, subject, message,
62
				mimetype.value(), res, mailhost.hostname, mailhost.port,
62
				mimetype.value(), res, mailhost.hostname, mailhost.port,
63
				mailhost.user, mailhost.password, charset, tls, ssl);
63
				mailhost.user, mailhost.password, charset, tls, ssl);
64
	}
64
	}
65
 
65
 
66
	private ReturnCode sendMail(String from, String replyto, String tolist,
66
	private ReturnCode sendMail(String from, String replyto, String tolist,
67
			String cclist, String bcclist, String subject, String message,
67
			String cclist, String bcclist, String subject, String message,
68
			String messagemimetype, FileSetResource attachments,
68
			String messagemimetype, FileSetResource attachments,
69
			String mailhost, int mailport, String user, String password,
69
			String mailhost, int mailport, String user, String password,
70
			String charset, boolean tls, boolean ssl) {
70
			String charset, boolean tls, boolean ssl) {
71
		EmailTask mail = new EmailTask();
71
		EmailTask mail = new EmailTask();
72
		mail.setTaskName("Mail");
72
		mail.setTaskName("Mail");
73
		RunTask runner = new RunTask(mail);
73
		RunTask runner = new RunTask(mail);
74
		mail.setFrom(from);
74
		mail.setFrom(from);
75
		mail.setReplyTo(replyto);
75
		mail.setReplyTo(replyto);
76
		mail.setToList(tolist);
76
		mail.setToList(tolist);
77
		mail.setCcList(cclist);
77
		mail.setCcList(cclist);
78
		mail.setBccList(bcclist);
78
		mail.setBccList(bcclist);
79
		mail.setSubject(subject);
79
		mail.setSubject(subject);
80
		mail.setMessage(message);
80
		mail.setMessage(message);
81
		mail.setMessageMimeType(messagemimetype);
81
		//mail.setMessageMimeType(messagemimetype);
82
		if (attachments != null) {
82
		if (attachments != null) {
83
			mail.addFileset(attachments.getAntResource(mail.getProject()));
83
			mail.addFileset(attachments.getAntResource(mail.getProject()));
84
		}
84
		}
85
		mail.setMailhost(mailhost);
85
		mail.setMailhost(mailhost);
86
		mail.setMailport(mailport);
86
		mail.setMailport(mailport);
87
		mail.setUser(user);
87
		mail.setUser(user);
88
		mail.setPassword(password);
88
		mail.setPassword(password);
89
		mail.setCharset(charset);
89
		mail.setCharset(charset);
90
		mail.setSSL(ssl);
90
		mail.setSSL(ssl);
91
		mail.setEnableStartTLS(tls);
91
		mail.setEnableStartTLS(tls);
92
		return runner.postTask();
92
		return runner.postTask();
93
	}
93
	}
94
}
94
}