public class SMTPProtocol extends java.lang.Object implements AuthenticationServer, java.lang.AutoCloseable
Modifier and Type | Field and Description |
---|---|
static int |
AUTHORIZED
Protocol state.
|
static int |
CC
Address type.
|
protected SMTPInputStream |
in |
static int |
NOT_CONNECTED
Protocol state.
|
protected java.io.OutputStream |
out |
static int |
PLAIN
Protocol state.
|
static int |
TO
Address type.
|
Constructor and Description |
---|
SMTPProtocol(java.lang.String host)
Constructs the SMTPProtocol.
|
SMTPProtocol(java.lang.String host,
int port)
Constructs the SMTPProtocol.
|
Modifier and Type | Method and Description |
---|---|
void |
auth(java.lang.String algorithm,
java.lang.String user,
char[] password)
Authenticates a user.
|
byte[] |
authReceive()
Receives the reponse of the server.
|
void |
authSend(byte[] call)
Sends the specified call of the SASL client to the server.
|
void |
close() |
SMTPResponse |
data(java.io.InputStream data)
Sends a DATA command which sends the mail to the recipients specified by the
RCPT command.
|
void |
dropConnection()
Drops the connection.
|
java.lang.String[] |
ehlo(java.net.InetAddress domain)
Sends the EHLO command to the server.
|
Address[] |
expand(Address mailinglist)
Expands a given mailinglist address to all members of that list.
|
java.lang.String |
getHostName()
Gets the hostname of the server.
|
java.lang.String |
getService()
Gets the service that is provided by the server.
|
int |
getState() |
void |
helo(java.net.InetAddress domain)
Sends the HELO command to the SMTP server.
|
void |
mail(Address from)
Sends a MAIL command which specifies the sender's email address and starts a
new mail.
|
void |
noop()
Sends a NOOP command to the server.
|
java.lang.String |
openPort()
Opens the connection to the SMTP server.
|
void |
quit()
Sends the QUIT command and closes the socket.
|
void |
rcpt(Address address)
Sends a RCPT TO: command which specifies a recipient of the mail started by
the MAIL command.
|
void |
rcpt(int type,
Address address)
Sends a RCPT command which specifies a recipient of the mail started by the
MAIL command.
|
void |
rcptWithDeliveryReport(Address address)
Sends a RCPT TO: NOTIFY=SUCCESS command which specifies a recipient of the
mail started by the MAIL command.
|
protected SMTPResponse |
readSingleLineResponse() |
void |
reset()
Sends a RSET command which resets the current session.
|
protected void |
sendCommand(java.lang.String command,
java.lang.String[] parameters) |
void |
startTLS()
Switches to a SSL connection using the TLS extension.
|
void |
verify(java.lang.String address)
Sends a VRFY command which verifies the given email address.
|
public static final int NOT_CONNECTED
public static final int PLAIN
public static final int AUTHORIZED
public static final int TO
public static final int CC
protected SMTPInputStream in
protected java.io.OutputStream out
public SMTPProtocol(java.lang.String host, int port)
host
- the sever name to connect toport
- the port to connect topublic SMTPProtocol(java.lang.String host)
host
- the sever name to connect topublic java.lang.String openPort() throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public void startTLS() throws java.io.IOException, javax.net.ssl.SSLException, SMTPException
java.io.IOException
javax.net.ssl.SSLException
SMTPException
protected void sendCommand(java.lang.String command, java.lang.String[] parameters) throws java.io.IOException
java.io.IOException
public java.lang.String[] ehlo(java.net.InetAddress domain) throws java.io.IOException, SMTPException
domain
- the domain name of the clientjava.io.IOException
SMTPException
helo(InetAddress)
public void helo(java.net.InetAddress domain) throws java.io.IOException, SMTPException
domain
- java.io.IOException
SMTPException
ehlo(InetAddress)
public void auth(java.lang.String algorithm, java.lang.String user, char[] password) throws java.io.IOException, SMTPException, AuthenticationException
algorithm
- algorithm
- the algorithm used to authenticate the user (e.g. PLAIN,
DIGEST-MD5)user
- the user namepassword
- the passwordjava.io.IOException
SMTPException
AuthenticationException
public void mail(Address from) throws java.io.IOException, SMTPException
from
- the email address of the senderjava.io.IOException
SMTPException
rcpt(Address)
,
data(InputStream)
public void rcpt(Address address) throws java.io.IOException, SMTPException
address
- the email address of a recipient.java.io.IOException
SMTPException
mail(Address)
,
data(InputStream)
public void rcptWithDeliveryReport(Address address) throws java.io.IOException, SMTPException
address
- the email address of a recipient.java.io.IOException
SMTPException
mail(Address)
,
data(InputStream)
public void rcpt(int type, Address address) throws java.io.IOException, SMTPException
type
- address
- the email address of a recipient.java.io.IOException
SMTPException
mail(Address)
,
data(InputStream)
,
TO
,
CC
public SMTPResponse data(java.io.InputStream data) throws java.io.IOException, SMTPException
data
- the mailjava.io.IOException
SMTPException
mail(Address)
,
rcpt(Address)
public void quit() throws java.lang.Exception
java.lang.Exception
public void reset() throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public void verify(java.lang.String address) throws java.io.IOException, SMTPException
address
- email address to verifyjava.io.IOException
SMTPException
public Address[] expand(Address mailinglist) throws java.io.IOException, SMTPException
mailinglist
- the mailinglist addressjava.io.IOException
SMTPException
public void noop() throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public byte[] authReceive() throws AuthenticationException, java.io.IOException
AuthenticationServer
authReceive
in interface AuthenticationServer
AuthenticationException
java.io.IOException
AuthenticationServer.authReceive()
public void authSend(byte[] call) throws java.io.IOException
AuthenticationServer
authSend
in interface AuthenticationServer
call
- the call of the client to the serverjava.io.IOException
AuthenticationServer.authSend(byte[])
public int getState()
public java.lang.String getHostName()
AuthenticationServer
getHostName
in interface AuthenticationServer
AuthenticationServer.getHostName()
public java.lang.String getService()
AuthenticationServer
getService
in interface AuthenticationServer
AuthenticationServer.getService()
public void dropConnection() throws java.lang.Exception
java.lang.Exception
protected SMTPResponse readSingleLineResponse() throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
Copyright © 2021. All Rights Reserved.