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);
};
};
date
date date(date dt)
MailMessage::Message
True
const True
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
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::Attachment
for backwards-compatibility only
Definition: SmtpClient.qm.dox.h:185
ConnectionProvider::AbstractConnection
MailMessage::Attachment
SmtpClient::Message
for backwards-compatibility and convenience
Definition: SmtpClient.qm.dox.h:169
SmtpClient
the SmtpClient namespace holds all public definitions in the SmtpClient module
Definition: SmtpClient.qm.dox.h:161
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 ...
hash
hash hash(object obj)