One of the common utilities that NeL provides is a very simple email (SMTP) interface for sending information emails. This could be useful for situations like crash reports. This system has two functions involved in its use:
void setDefaultEmailParams(const std::string &smtpServer, const std::string &from, const std::string &to);
bool sendEmail(const std::string &smtpServer,
const std::string &from,
const std::string &to,
const std::string &subject,
const std::string &body,
const std::string &attachedFile,
bool onlyCheck);
The setDefaultEmailParams
function sets default values for the SMTP server to use, the From email address and the To email address. You can call this method to set those for all subsequent calls to sendEmail
- this allows you to send empty strings to this function thus using the default.
Do not use the setDefaultEmailParams
function from within a NLNET service since the service already accomodates this through config file variables. If you wish to use sendEmail
from within a service you need to change the following config file variables in the service config file:
Actually sending emails through this function is very easy. Note that if you configured the defaults using a config file (for services) or through a call to setDefaultEmailParams
you can use empty strings (e.g. "") for the first three parameters: server, from and to. The next two arguments, subject and body, are required and should reflect the subject and body of the email you would like to send. The final two arguments, attachedFile
and onlyChec
, are optional. The onlyCheck
flag is false
by default. It tells the email functionality to mock sending the email but not actual complete the transmission and is useful for testing but not likely to be used in production code.
The attachedFile
argument is also optional but should contain the path and filename of the file you want to send. The email functionality will look up the file, determine the MIME-type based on a limited hard coded list and then uuencode it so that it appears as a standard attachment in standards-complant mail clients.
// Send an email using the defaults defined by the service (config file) or by a previous call to setDefaultEmailParams().
sendEmail("", "", "", "Test email.", "This is just a test, probably something important.");