Click on a class name to see the description of that particular class:
static string SendMailAsync(string host, string from, string to, string text, string filePath, unsigned minutes, string auth)
Begins a send of an asyncronous email message
The SendMailAsync works in a simple fashion. When the method is called, the email message is stored in a special format within the file specified by the filePath parameter. Once this step is completed, Biferno continues to process the current script with no further interruption, while another process running in parallel has the task of asynchronously sending the queued messages.
If an error occurs, Biferno will try to send the message again at regular intervals, until the timeout specified by the minutes parameter is reached. For this reason using the SendMailAsync method not only makes script execution faster, but also increases the likelihood that a message can be successfully sent in presence of temporary error conditions.
All attempts to send a message, i.e. the conversational protocol exchanges with the SMTP server, are stored in a log file in the same directory as the message file. The log file has the same name of the message file with the extension “.log” appended. The message file, together with the corresponding log file, is deleted from disk after the message has been successfully sent or after the timeout period expires.
The SendMailAsync method returns a string containing the file path of the message, including the name with which it has been stored on disk. This is because an ".xml" suffix is prepended and, if the file specified by the filePath parameter already exists, the method appends a progressive number to the file name.
specifies the name or address of the SMTP server we want to use to send our email
specifies the email address to be used as the address of the sender of the message. This is the user who contacts the smtp server and can be also different from the header field "From" (if any)
is the email address of the receiver, i.e. the person we want to address the message to. Can be also a sequence of adresses (comma separated)
is the message text, possibly including part of the SMTP header (in particular the subject field)
specifies the path of the file where the message is temporarily stored while it waits to be sent to the server
defines the timeout, in minutes, after which Biferno will stop trying to send the message in case of repeated errors
The following script shows how to use the SendMailAsync method. The script sends a message to a number of email addresses stored in an array, which could be filled e.g. by a database query.
email_host = "mailserver.mydomain.com"
email_from = "email@example.com"
email_text = "Subject: SendMailAsync Test\r\n\r\n"
email_text += "Test email body."
email_timeout = 120 // Two hours
arr_email = array("firstname.lastname@example.org", "email@example.com",
n_email = arr_email.dim
email_sent = 0
for (i = 1; i <= n_email; i++)
email_to = arr_email[i]
email_file = "emails/email_" + email_sent
smtp.SendMailAsync(email_host, email_from, email_to,
email_text, email_file, email_timeout)
The format of a file is XML.
Return to the smtp class