All Classes Namespaces Functions Variables Groups Pages
SmtpClient.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file SmtpClient.qm SmtpClient module definition
/* SmtpClient.qm Copyright 2012 - 2017 Qore Technologies, s.r.o.
Original Authors: Wolfgang Ritzinger, Marian Bonda, Pavol Potoncok
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum qore version
// need mime definitions
// need MailMessage classes
// assume local var scope, do not use "$" for vars, members, and method calls
namespace SmtpClient {
const DefaultReadTimeout = 15s;
const DefaultConnectTimeout = 30s;
class Message : public MailMessage::Message {
public:
constructor(string sender, string subject) ;
};
class Attachment : public MailMessage::Attachment {
public:
};
class SmtpClient {
public:
private :
Socket sock();
// connect string
string connect;
// ensures exclusive access to the object
Mutex mutex();
bool nosend = False;
// optional info log closure
*code log_info;
// optional debug log closure
*code log_debug;
// tls flag (ie \c "STARTTLS" flag; ie application layer security)
bool tls = False;
// ssl flag (for TLS/SSL connections - ie transport layer instead of application layer security)
bool ssl = False;
// esmtp flag
bool esmtp;
// authentication credentials
*string user;
*string pass;
// logged in flag
bool logged_in = False;
// read timeout in milliseconds
timeout readTimeout = DefaultReadTimeout;
// connect timeout in milliseconds
timeout connectTimeout = DefaultConnectTimeout;
// HELO/EHLO reply
hash hello_reply;
const MaxDebugLine = 2048;
public:
public :
const SmtpPort = 25;
const SmtpsPort = 465;
const EsmtpPort = 587;
const Protocols = (
"smtp": (
"port": SmtpPort,
"ssl": False,
"tls": False,
),
"smtps": (
"port": SmtpsPort,
"ssl": True,
"tls": False,
),
"smtptls": (
"port": SmtpsPort,
"ssl": False,
"tls": True,
),
"esmtp": (
"port": EsmtpPort,
"ssl": False,
"tls": False,
),
"esmtptls": (
"port": EsmtpPort,
"ssl": False,
"tls": True,
),
);
public:
constructor(string host, softint port, *code log, *code dbglog);
constructor(string url, *code log, *code dbglog);
destructor();
tls(bool n_tls);
bool tls();
ssl(bool n_ssl);
bool ssl();
setUserPass(string n_user, string n_pass);
test(bool ns);
bool test();
connect();
bool isConnected();
disconnect();
setReadTimeout(timeout to);
int getReadTimeoutMs();
date getReadTimeoutDate();
setConnectTimeout(timeout to);
int getConnectTimeoutMs();
date getConnectTimeoutDate();
hash sendMessage(MailMessage::Message message);
forceDisconnect();
nothing clearWarningQueue();
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms = 1s);
hash getUsageInfo();
clearStats();
// don't reimplement this method; fix/enhance it in the module
private:
final disconnectIntern();
public:
private:
log(string msg);
public:
private:
logDbg(string msg);
public:
private:
connectIntern();
public:
private:
loginIntern();
public:
// send data over the socket
private:
sendDataIntern(data str);
public:
// send data and log in the debug log if set
private:
sendData(string str);
public:
// send data and log in the debug log if set
private:
sendData(binary b);
public:
// send a command over the socket and return the response as a hash
// don't reimplement this method; fix/enhance it in the module
private:
final hash sendCommand(string str);
public:
// read a line from the socket (terminated with \n)
private:
string readLine(timeout to);
public:
// sends the message header (without body & attachments) to the SMTP server
// don't reimplement this method; fix/enhance it in the module
private:
final hash sendMessageInfoIntern(MailMessage::Message message);
public:
private:
forceDisconnectIntern();
public:
};
class SmtpConnection : public ConnectionProvider::AbstractConnection {
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
string getType();
*hash getRuntimeOptions();
private:
SmtpClient getImpl(bool connect = True, *hash rtopts);
public:
static SmtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
};
SmtpClient::SmtpConnection::getRuntimeOptions
*hash getRuntimeOptions()
returns runtime options
ConnectionProvider::AbstractConnection::monitor
bool monitor
date
date date(date dt)
SmtpClient::SmtpClient::getConnectTimeoutDate
date getConnectTimeoutDate()
returns the connect timeout as a relative time value
SmtpClient::SmtpClient::SmtpPort
const SmtpPort
default SMTP port
Definition: SmtpClient.qm.dox.h:247
SmtpClient::SmtpClient
the class that&#39;s used to communicate with an SMTP server and supports optional TLS/SSL encryption ...
Definition: SmtpClient.qm.dox.h:194
SmtpClient::SmtpClient::getReadTimeoutMs
int getReadTimeoutMs()
returns the read timeout as an integer giving milliseconds
SmtpClient::SmtpConnection::getImpl
SmtpClient getImpl(bool connect=True, *hash rtopts)
returns an SmtpClient object
MailMessage::Message
ConnectionProvider::AbstractConnection::opts
*hash opts
True
const True
SmtpClient::SmtpClient::setConnectTimeout
setConnectTimeout(timeout to)
sets the connect timeout
ConnectionProvider::AbstractConnection::name
string name
SmtpClient::SmtpConnection::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the SmtpConnection object
SmtpClient::SmtpClient::tls
bool tls()
returns the TLS/SSL flag
binary
binary binary()
SmtpClient::DefaultReadTimeout
const DefaultReadTimeout
15 second read timeout
Definition: SmtpClient.qm.dox.h:163
SmtpClient::DefaultConnectTimeout
const DefaultConnectTimeout
30 second connect timeout
Definition: SmtpClient.qm.dox.h:166
ConnectionProvider::AbstractConnection::urlh
hash urlh
SmtpClient::SmtpClient::destructor
destructor()
disconnects if connected and destroys the object
False
const False
SmtpClient::SmtpConnection
class for SMTP connections; returns an object of class SmtpClient for sending emails ...
Definition: SmtpClient.qm.dox.h:594
SmtpClient::SmtpConnection::getType
string getType()
returns &quot;smtp&quot;
SmtpClient::Attachment
for backwards-compatibility only
Definition: SmtpClient.qm.dox.h:185
ConnectionProvider::AbstractConnection
SmtpClient::SmtpClient::constructor
constructor(string host, softint port, *code log, *code dbglog)
creates the SmtpClient object
SmtpClient::SmtpClient::forceDisconnect
forceDisconnect()
force disconnect of socket without error
MailMessage::Attachment
SmtpClient::SmtpClient::clearWarningQueue
nothing clearWarningQueue()
Removes any warning Queue object from the Socket.
SmtpClient::SmtpConnection::make
static SmtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
SmtpClient::SmtpClient::ssl
bool ssl()
returns the SSL connection flag
SmtpClient::SmtpClient::EsmtpPort
const EsmtpPort
default ESMTP port
Definition: SmtpClient.qm.dox.h:253
SmtpClient::SmtpClient::setUserPass
setUserPass(string n_user, string n_pass)
sets the username and password for authenticated connections
SmtpClient::SmtpClient::getReadTimeoutDate
date getReadTimeoutDate()
returns the read timeout as a relative time value
SmtpClient::Message
for backwards-compatibility and convenience
Definition: SmtpClient.qm.dox.h:169
SmtpClient::SmtpClient::disconnect
disconnect()
disconnect from the server
ConnectionProvider::AbstractConnection::desc
string desc
SmtpClient::SmtpClient::isConnected
bool isConnected()
return connection status
SmtpClient::SmtpClient::test
bool test()
returns the test mode flag
SmtpClient::Message::constructor
constructor(string sender, string subject)
creates a Message object from the arguments given; this variant of the constructor is designed to be ...
SmtpClient::SmtpClient::sendMessage
hash sendMessage(MailMessage::Message message)
send a Message to the server
SmtpClient::SmtpClient::connect
connect()
Connect to the server with the connection parameters set in the constructor()
SmtpClient::SmtpClient::SmtpsPort
const SmtpsPort
default SMTPS port; note that this port is currently assigned to source-specific multicast audio/vide...
Definition: SmtpClient.qm.dox.h:250
ConnectionProvider::AbstractConnection::url
string url
SmtpClient::SmtpClient::setWarningQueue
nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms=1s)
Sets a Queue object to receive socket warnings.
SmtpClient::SmtpClient::Protocols
const Protocols
procotol config
Definition: SmtpClient.qm.dox.h:256
hash
hash hash(object obj)
SmtpClient::SmtpClient::getConnectTimeoutMs
int getConnectTimeoutMs()
returns the connect timeout as an integer giving milliseconds
SmtpClient::SmtpClient::setReadTimeout
setReadTimeout(timeout to)
sets the read timeout
SmtpClient::SmtpClient::clearStats
clearStats()
Clears performance statistics.
SmtpClient::SmtpClient::getUsageInfo
hash getUsageInfo()
Returns performance statistics for the socket.