Package javaforce
Class SMTP
java.lang.Object
javaforce.SMTP
SMTP client class.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd date header to email.voidAdd custom header to email.booleanAuthenticates with SMTP Server using AUTH_LOGIN type.booleanAuthenticates with SMTP Server.voidSets bcc email for message.voidSets cc email for message.voidSend any command to server.booleanConnects to an insecure SMTP server.booleanconnectSSL(String host, int port) Connects to a secure SMTP server.booleanSends a simple text message with headers included.booleandata(String body_text, String body_html, SMTP.Attachment[] attachments) Sends an enhanced message in text and/or html formats with headers and optional attachments.voidDisconnect from SMTP Server.voidSets from email for message.Returns last line of response from last command sent.booleanlogin()Sends HELO / EHLO command.voidlogout()Send QUIT command.static voidCLIvoidsetContentType(String type) Sets content type header of body.static voidsetDebug(boolean state) Set debug logging state.static voidsetLog(int id) voidstarttls()Secures connection using STARTTLS command.voidSets subject header for email.voidSets to email for message.
-
Field Details
-
debug
public static boolean debug -
debug_log
public static boolean debug_log -
log
public static int log -
response
Holds the repsonse strings from the last executed command -
PORT
public static final int PORT- See Also:
-
TLSPORT
public static final int TLSPORT- See Also:
-
SSLPORT
public static final int SSLPORT- See Also:
-
AUTH_PLAIN
- See Also:
-
AUTH_LOGIN
- See Also:
-
AUTH_NTLM
- See Also:
-
-
Constructor Details
-
SMTP
public SMTP()
-
-
Method Details
-
connect
Connects to an insecure SMTP server.- Parameters:
host- = SMTP serverport- = port to connect (default = 25 or 587)- Throws:
Exception
-
connectSSL
Connects to a secure SMTP server.- Parameters:
host- = SMTP serverport- = port to connect (default = 465)- Throws:
Exception
-
disconnect
Disconnect from SMTP Server.- Throws:
Exception
-
setDebug
public static void setDebug(boolean state) Set debug logging state. -
setLog
public static void setLog(int id) -
login
Sends HELO / EHLO command.- Throws:
Exception
-
auth
Authenticates with SMTP Server.- Parameters:
user- = usernamepass- = passwordtype- = auth type (AUTH_LOGIN or AUTH_NTML)- Throws:
Exception
-
auth
Authenticates with SMTP Server using AUTH_LOGIN type.- Parameters:
user- = usernamepass- = password- Throws:
Exception
-
logout
Send QUIT command.- Throws:
Exception
-
cmd
Send any command to server.- Throws:
Exception
-
starttls
Secures connection using STARTTLS command.- Throws:
Exception
-
from
Sets from email for message.- Parameters:
email- = from email address- Throws:
Exception
-
to
Sets to email for message.- Parameters:
email- = to email address- Throws:
Exception
-
cc
Sets cc email for message.- Parameters:
email- = cc email address- Throws:
Exception
-
bcc
Sets bcc email for message.- Parameters:
email- = bcc email address- Throws:
Exception
-
data
Sends a simple text message with headers included. The terminating \r\n.\r\n will be added.- Parameters:
msg- = email headers + blank line + message body- Throws:
Exception
-
subject
Sets subject header for email.- Parameters:
subject- = subject of email Can only be used with enhanced data() method.
-
setContentType
Sets content type header of body.- Parameters:
type- = "text/plain" or "text/html" (default is unspecified) Can only be used with enhanced data() method.
-
addDate
Add date header to email. Can only be used with enhanced data() method. -
addHeader
Add custom header to email. Can only be used with enhanced data() method. -
data
public boolean data(String body_text, String body_html, SMTP.Attachment[] attachments) throws Exception Sends an enhanced message in text and/or html formats with headers and optional attachments. Headers are automatically generated and MUST NOT be included in body. One or both of body_text, body_html MUST be supplied.- Parameters:
body_text- = body of message in TEXT formatbody_html- = body of message in HTML formatattachments- = files to attach- Throws:
Exception
-
getLastResponse
Returns last line of response from last command sent. -
main
CLI
-