public void send() throws MailException
{
try (
- Socket sock = new Socket(m_smtpHost, m_smtpPort);
+ Socket sock = openSocket(m_smtpHost, m_smtpPort);
PrintWriter pw = new PrintWriter(sock.getOutputStream(), true);
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
)
}
}
+ Socket openSocket(String host, int port) throws UnknownHostException, IOException {
+ return new Socket(host, port);
+ }
+
String getHostName() throws UnknownHostException {
if (null == m_hostName) {
m_hostName = InetAddress.getLocalHost().getHostName();
validateResponse("", RESP_220, line);
cmd = "HELO " + getHostName();
+ line = sendLine(pw, br, cmd);
validateResponse(cmd, RESP_250, line);
cmd = "MAIL FROM: " + m_from;
sendLine(pw, "Content-Type: " + part.getMimeType()); // TODO: Add support for encodings
sendLine(pw, "");
sendLine(pw, part.getContent());
+ sendLine(pw, "");
}
sendLine(pw, "--" + getBoundary() + "--");
}
}
}
- void validateResponse(String cmd, String actual, String expected) throws MailException
+ void validateResponse(String cmd, String expected, String actual) throws MailException
{
if (! actual.startsWith(expected)) {
throw new MailException(cmd, expected, actual);
void sendLine(PrintWriter pw, String line)
{
pw.write(line + "\r\n");
+ pw.flush();
}
String sendLine(PrintWriter pw, BufferedReader br, String line) throws IOException