Added simple mail operation
git-svn-id: https://brutex.net/svn/xservices/trunk@18 e7e49efb-446e-492e-b9ec-fcafc1997a86tag-20130205r
parent
7db3e8dd21
commit
e192472e63
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.brutex.xservices.types;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Rosenberger, bru@brutex.de
|
||||
*/
|
||||
@XmlType(name="connection")
|
||||
public class HostConnection {
|
||||
|
||||
public HostConnection() {
|
||||
}
|
||||
|
||||
@XmlElement(name="hostname", required=false, nillable=false)
|
||||
public String hostname;
|
||||
|
||||
@XmlElement(name="port", required=false, nillable=false)
|
||||
public int port;
|
||||
|
||||
@XmlElement(name="user", required=false, nillable=false)
|
||||
public String user;
|
||||
|
||||
@XmlElement(name="password", required=false, nillable=false)
|
||||
public String password;
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ public class RunTask {
|
|||
log = new TimestampedLogger();
|
||||
log.setOutputPrintStream(new PrintStream(out));
|
||||
log.setErrorPrintStream(new PrintStream(err));
|
||||
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
|
||||
log.setMessageOutputLevel(Echo.EchoLevel.WARN.getLevel());
|
||||
|
||||
antproject.addBuildListener(log);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package net.brutex.xservices.ws;
|
|||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebService;
|
||||
import net.brutex.xservices.types.HostConnection;
|
||||
import net.brutex.xservices.types.ReturnCode;
|
||||
import net.brutex.xservices.util.BrutexNamespaces;
|
||||
|
||||
|
@ -31,4 +32,11 @@ public interface MiscService {
|
|||
|
||||
@WebMethod(operationName="getHostinfo")
|
||||
public ReturnCode getHostinfo(@WebParam(name="hostname") String hostname);
|
||||
|
||||
@WebMethod(operationName="sendMailSimple")
|
||||
public ReturnCode sendMailSimple(@WebParam(name="mailhost") HostConnection mailhost,
|
||||
@WebParam(name="from") String from,
|
||||
@WebParam(name="to") String tolist,
|
||||
@WebParam(name="subject") String subject,
|
||||
@WebParam(name="message") String message);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,13 @@
|
|||
package net.brutex.xservices.ws;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import net.brutex.xservices.types.FileSetResource;
|
||||
import net.brutex.xservices.types.HostConnection;
|
||||
import net.brutex.xservices.types.ReturnCode;
|
||||
import net.brutex.xservices.util.RunTask;
|
||||
import org.apache.tools.ant.taskdefs.HostInfo;
|
||||
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
||||
import org.apache.tools.ant.taskdefs.email.Mailer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -30,15 +34,76 @@ serviceName="MiscService")
|
|||
public class MiscServiceImpl implements MiscService {
|
||||
|
||||
public ReturnCode getHostinfo(String hostname) {
|
||||
return antGetHostinfo(hostname, "");
|
||||
return antGetHostinfo(hostname, null);
|
||||
}
|
||||
|
||||
public ReturnCode sendMailSimple(HostConnection mailhost, String from, String tolist, String subject, String message) {
|
||||
return sendMail(from,
|
||||
from,
|
||||
tolist,
|
||||
"",
|
||||
"",
|
||||
subject,
|
||||
message,
|
||||
"text/plain",
|
||||
null,
|
||||
mailhost.hostname,
|
||||
mailhost.port,
|
||||
mailhost.user,
|
||||
mailhost.password,
|
||||
"utf-8",
|
||||
false,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ReturnCode antGetHostinfo(String hostname, String prefix) {
|
||||
HostInfo info = new HostInfo();
|
||||
info.setTaskName("HostInfo");
|
||||
RunTask runner = new RunTask(info);
|
||||
info.setHost(hostname);
|
||||
info.setPrefix(prefix);
|
||||
//info.setPrefix(prefix);
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
private ReturnCode sendMail(String from,
|
||||
String replyto,
|
||||
String tolist,
|
||||
String cclist,
|
||||
String bcclist,
|
||||
String subject,
|
||||
String message,
|
||||
String messagemimetype,
|
||||
FileSetResource attachments,
|
||||
String mailhost,
|
||||
int mailport,
|
||||
String user,
|
||||
String password,
|
||||
String charset,
|
||||
boolean tls,
|
||||
boolean ssl) {
|
||||
EmailTask mail = new EmailTask();
|
||||
mail.setTaskName("Mail");
|
||||
RunTask runner = new RunTask(mail);
|
||||
mail.setFrom(from);
|
||||
mail.setReplyTo(replyto);
|
||||
mail.setToList(tolist);
|
||||
mail.setCcList(cclist);
|
||||
mail.setBccList(bcclist);
|
||||
mail.setSubject(subject);
|
||||
mail.setMessage(message);
|
||||
mail.setMessageMimeType(messagemimetype);
|
||||
if(attachments != null) {
|
||||
mail.addFileset(attachments.getAntFileSet(mail.getProject()));
|
||||
}
|
||||
mail.setMailhost(mailhost);
|
||||
mail.setMailport(mailport);
|
||||
mail.setUser(user);
|
||||
mail.setPassword(password);
|
||||
mail.setCharset(charset);
|
||||
mail.setSSL(ssl);
|
||||
mail.setEnableStartTLS(tls);
|
||||
return runner.postTask();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue