Qore SmtpClient Module Reference
1.2
|
the class that's used to communicate with an SMTP server and supports optional TLS/SSL encryption More...
Public Member Functions | |
constructor (string host, softint port, *code log, *code dbglog) | |
creates the SmtpClient object | |
constructor (string url, *code log, *code dbglog) | |
creates the SmtpClient object | |
destructor () | |
disconnects if connected and destroys the object | |
tls (bool tls) | |
sets the TLS/SSL flag | |
bool | tls () |
returns the TLS/SSL flag | |
ssl (bool ssl) | |
sets the SSL connection flag | |
bool | ssl () |
returns the SSL connection flag | |
setUserPass (string user, string pass) | |
sets the username and password for authenticated connections | |
test (bool ns) | |
sets or disables test mode; no connections are made in test mode | |
bool | test () |
returns the test mode flag | |
connect () | |
Connect to the server with the connection parameters set in the constructor() | |
bool | isConnected () |
return connection status | |
disconnect () | |
disconnect from the server | |
setReadTimeout (timeout to) | |
sets the read timeout | |
int | getReadTimeoutMs () |
returns the read timeout as an integer giving milliseconds | |
date | getReadTimeoutDate () |
returns the read timeout as a relative time value | |
setConnectTimeout (timeout to) | |
sets the connect timeout | |
int | getConnectTimeoutMs () |
returns the connect timeout as an integer giving milliseconds | |
date | getConnectTimeoutDate () |
returns the connect timeout as a relative time value | |
hash | sendMessage (MailMessage::Message message) |
send a Message to the server | |
forceDisconnect () | |
force disconnect of socket without error | |
Public Attributes | |
string | mpboundary = replace(makeBase64String(string(now_us())), "=", "") |
create a different multipart boundary string every time based on the current time | |
const | SmtpPort = 25 |
default SMTP port | |
const | SmtpsPort = 465 |
default SMTPS port; note that this port is currently assigned to source-specific multicast audio/video (http://www.iana.org/assignments/port-numbers); it's use as a port for secure SMTP listeners (where security is enforced at the transport layer because the server immediately negotiates a TLS/SSL connection before the application protocol communication starts) is deprecated | |
const | EsmtpPort = 587 |
default ESMTP port | |
const | Protocols |
procotol config | |
the class that's used to communicate with an SMTP server and supports optional TLS/SSL encryption
This class uses a Mutex lock in each SmtpClient object to ensure thread serialization to the underlying socket and its internal configuration, so it is safe to access in a multithreaded context.
SmtpClient::SmtpClient::connect | ( | ) |
Connect to the server with the connection parameters set in the constructor()
SmtpClient::SmtpClient::constructor | ( | string | host, |
softint | port, | ||
*code | log, | ||
*code | dbglog | ||
) |
creates the SmtpClient object
host | the hostname of the SMTP server (use "[hostname]" to explicitly specify an ipv6 connection) |
port | the port number of the SMTP server |
log | a closure or call reference for log messages; a single string argument will be passed to this code for logging |
dbglog | a closure for debugging/technical log messages; a single string argument will be passed to this code for logging |
SmtpClient::SmtpClient::constructor | ( | string | url, |
*code | log, | ||
*code | dbglog | ||
) |
creates the SmtpClient object
url | the URL of the SMTP server (use "[hostname]" or "[address]" for ipv6 connections); if no protocol (scheme) and no port is given for non-UNIX sockets, then SmtpPort is used as the default port number. This argument is parsed with parse_url(); see smtpclient_protocols for a description of the handling of the protocol (scheme) component of the URL including default ports per protocol (scheme). If an unknown protocol (scheme) is given then a SMTP-UNKNOWN-PROTOCOL exception is raised |
log | an optional closure or call reference for log messages; a single string argument will be passed to this code for logging |
dbglog | an optional closure or call reference for debugging/technical log messages; a single string argument will be passed to this code for logging |
PARSE-URL-ERROR | the url argument could not be parsed with parse_url() |
SMTPCLIENT-UNKNOWN-PROTOCOL | the protocol (scheme) given is unknown or unsupported |
SMTPCLIENT-INVALID-AUTHENTICATION | partial authentication credentials passed; the username or password is missing |
SmtpClient::SmtpClient::destructor | ( | ) |
disconnects if connected and destroys the object
if any exceptions occur during the disconnection, they are sent to the debug log closure/call reference
SmtpClient::SmtpClient::disconnect | ( | ) |
disconnect from the server
SmtpClient::SmtpClient::forceDisconnect | ( | ) |
force disconnect of socket without error
hash SmtpClient::SmtpClient::sendMessage | ( | MailMessage::Message | message | ) |
send a Message to the server
message | the Message to send |
"code"
: the return code, "desc"
: the string description):HELO
or EHLO:
a hash of the reply received from the HELO
or EHLO
commandRCPT:
hash keyed by email address with hash return structures values for the RCPT TO commandMSGID:
return structure after the send; generally contains message idQUIT:
the server response of the disconnect commandMESSAGE-ERROR | the message is incomplete and cannot be sent |
sets the username and password for authenticated connections
user | the username to set for authentication |
pass | the password to set for authentication |
SmtpClient::SmtpClient::ssl | ( | bool | ssl | ) |
sets the SSL connection flag
ssl | if True then connections to the SMTP server will immediately try to negotiate transport layer TSL/SSL security; will also in this case turn off the TLS/SSL "STARTTLS" application layer security flag |
SmtpClient::SmtpClient::tls | ( | bool | tls | ) |
sets the TLS/SSL flag
tls | if True then use TLS/SSL; if the TLS/SSL flag is set then the client will issue a "STARTTLS" command after connecting and negotiate a secure TLS/SSL connection to the server; will also in this case turn off the SSL connection flag |