After we create the an
email_message object with
compose_email(), we can choose to send it through an SMTP server using blastula’s
smtp_send() function. There is some system setup required before sending a blastula email message via SMTP. The main considerations are:
We’ll go through each of these setup steps before getting into several sending examples with
Before using Gmail to send out email through blastula, there is a key Gmail account setting that must changed from the default value. We have to allow Less Secure Apps to use your the Gmail account. Details on how to make this account-level change can be found in this support document.
While we can provide SMTP login and configuration information directly whenever we send email, it can be convenient to store this data for easy retrieval. It should be noted that the manually specifying credentials is more secure since no sensitive information is ever stored on disk (and password entry is obscured). Should you want to store credentials on-disk, however, there are two methods available for this:
The first method is more secure since access to the system-wide key-value store requires authentication. The second is less secure since it is the user’s responsibility to manage the resulting human-readable JSON file. We’ll provide examples on how to use the both options effectively.
We can store email credentials in the system key-value store with the
create_smtp_creds_key() function. Here is an example showing how to create an entry with an
When executing this function, there will always be a prompt for the password (i.e., there is no
password argument in this function).
We can also use preset SMTP settings. For example, if we would like to send email through Gmail, we can supply
provider = gmail to not have to worry about the SMTP server details.
The credentials data can be later retrieved during email sending with the
creds_key() credentials helper. Should you need to know which keys are set in the key-value store, we can use the
view_credential_keys() function (which shows all keys by
We can store email credentials in a file using the
create_smtp_creds_file() function. Here is an example showing how to create a credentials file with the name
"gmail_creds" in the working directory.
We can also use preset SMTP settings as with the
create_smtp_creds_key() function. To send email through Gmail we can supply
provider = gmail to avoid supplying
The credentials data from this file can later retrieved during email sending with the
creds_file() credentials helper.
Let’s create a simple test message with the
The test message
Now that this test message is available, we can experiment with the sending of it to a personal email account. Here are three examples, each use a different method for supplying SMTP credentials.
If the SMTP credentials are correctly set, we will get the following message in the console:
The email message was sent successfully.
This covers the basics on how to get up and running on sending emails through blastula’s SMTP functionality. Again, this article applies only to the in-development version of blastula, which can be installed using:
smtp_send() is quite new, there are bound to be some problems with it. If you encounter a bug or just have a question or feature request, please file an issue.