Renamed smtp client and fix non flushing issue

This commit is contained in:
Ziver Koc 2017-01-20 13:25:49 +01:00
parent 7664b4bf00
commit 16f3d6fc60
4 changed files with 40 additions and 6 deletions

View file

@ -7,7 +7,7 @@ import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;
import static zutil.net.smtp.SMTPClient.NEWLINE;
import static zutil.net.smtp.SmtpClient.NEWLINE;
/**

View file

@ -40,7 +40,7 @@ import java.util.logging.Logger;
* @author Ziver
*
*/
public class SMTPClient {
public class SmtpClient {
private static final Logger logger = LogUtil.getLogger();
protected static final String NEWLINE = "\r\n";
@ -62,16 +62,16 @@ public class SMTPClient {
/**
* Will look for a SMTP server on localhost on port 25
*/
public SMTPClient() throws IOException {
public SmtpClient() throws IOException {
this("localhost", 25);
}
/**
* Will look for a SMTP server on specified host on port 25
*/
public SMTPClient(String host) throws IOException {
public SmtpClient(String host) throws IOException {
this(host, 25);
}
public SMTPClient(String host, int port) throws IOException {
public SmtpClient(String host, int port) throws IOException {
socket = new Socket(host, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new OutputStreamWriter(socket.getOutputStream());
@ -80,6 +80,8 @@ public class SMTPClient {
sendCommand(CMD_HELO + " " + InetAddress.getLocalHost().getHostName());
}
/**
* Sends a basic email to the smtp server
*
@ -133,6 +135,7 @@ public class SMTPClient {
public synchronized int sendCommand(String cmd) throws IOException{
logger.finest(">> "+cmd);
out.write(cmd + NEWLINE);
out.flush();
String reply = readCommand();
return parseReturnCode(reply);
}