Send email messages using the Mailgun messaging service. Supports both US and EU API endpoints.
Mailgun Account Required
A valid Mailgun account and the proper configuration must be set up to use the email module. See the Configuration section below. The Mailgun messaging service allows you to send up to 10,000 free email messages a month.
Screencast Available
Learn about sending email in a screencast format by Clicking here.
new
Create a new email message object.
core.email.new()
Parameters
This method does not require any parameters.
If you need to make a call to a different Mailgun domain other than your default see Overriding Defaults.
Returns
A new email message object based on the default Mailgun credentials.
Example
local msg = core.email.new()
Message Object
to
The address(es) to send the message to. Multiple values must be seperated by a comma. This is a required value.
msg:to( address[, addressN] )
Parameters
Name | Description | Type |
---|---|---|
address | The recipient address(es). | String |
Examples
Single address:
--Address only msg:to("user@email.com") --With name msg:to("Chris <user@email.com>")
Multiple addresses:
msg:to("user1@email.com", "Jim <user2@email.com>")
from
The message sender address. This is a required value.
msg:from( address )
Parameters
Name | Description | Type |
---|---|---|
address | The sender address. | String |
Example
msg:from("sender@email.com")
cc
The address(es) to "cc" the message to. Multiple values must be seperated by a comma.
msg:cc( address[, addressN] )
Parameters
Name | Description | Type |
---|---|---|
address | The "cc" address(es). | String |
Examples
Single address:
--Address only msg:cc("user@email.com") --With name msg:cc("Chris <user@email.com>")
Multiple addresses:
msg:cc("user1@email.com", "Jim <user2@email.com>")
bcc
The address(es) to "bcc" the message to. Multiple values must be seperated by a comma.
msg:bcc( address[, addressN] )
Parameters
Name | Description | Type |
---|---|---|
address | The "bcc" address(es). | String |
Examples
Single address:
--Address only msg:bcc("user@email.com") --With name msg:bcc("Chris <user@email.com>")
Multiple addresses:
msg:bcc("user1@email.com", "Jim <user2@email.com>")
replyTo
Sets a specific reply-to address. If not set, the sender address is the default.
msg:replyTo( address )
Parameters
Name | Description | Type |
---|---|---|
address | A specific reply-to address. | String |
Example
msg:replyTo("Support <support@email.com>")
subject
The subject line for the email. The default is "(no subject)" if not provided.
msg:subject( subject_str )
Parameters
Name | Description | Type |
---|---|---|
subject_str | The subject title. | String |
Example
msg:subject("A Super Email")
text
The plain text version of the message body.
msg:text( message_str )
Parameters
Name | Description | Type |
---|---|---|
message_str | A plain string message. | String |
Example
msg:text("Here is your plain information.")
html
The html version of the message body.
msg:html( message_html )
Parameters
Name | Description | Type |
---|---|---|
message_html | An html string message. | String |
Example
msg:html("Here is your <b>bold</b> information.")
tag
Sets a specific tag for the email. Can be used for tracking in Mailgun.
msg:tag( tag_str )
Parameters
Name | Description | Type |
---|---|---|
tag_str | A string tag for tracking. | String |
Example
msg:tag("appuser")
requireTls
Force Mailgun to use TLS when sending the message. Defaults to false.
msg:requireTls( bool )
Parameters
Name | Description | Type |
---|---|---|
bool | Whether to enable TLS for this message. | Boolean |
Example
msg:requireTls(true)
skipVerification
Skip certificate verification when using TLS. Defaults to false.
msg:skipVerification( bool )
Parameters
Name | Description | Type |
---|---|---|
bool | Whether to skip verification in TLS. | Boolean |
Example
msg:skipVerification(true)
testMode
Used for debugging in Mailgun. Defaults to false.
msg:testMode( bool )
Parameters
Name | Description | Type |
---|---|---|
bool | Whether to enable test mode. | Boolean |
Example
msg:testMode(true)
send
Send the final message via Mailgun.
msg:send()
Parameters
This method takes no parameters.
Example
local resp, err = msg:send()
Configuration
To use the Email module you will need a valid Mailgun account.
Once you have your account set-up you will need to provide your Sending Domain, Secret API Key, and API Region from Mailgun to your Coronium Core system.
Using the Webmin, navigate to the Config section and enter the requested information in the Mailgun Settings area. Click the update button to enable your credentials.
You can now use the Email module for sending email.
Overriding Defaults
You can also pass your Mailgun options directly in the new
method. This can be useful when you need to send from another Mailgun domain besides your default.
core.email.new(key, domain[, region])
Parameters
Name | Description | Type | Required |
---|---|---|---|
key | A Mailgun API key. | String | Y |
domain | A verified Mailgun domain. | String | Y |
region | A Mailgun API region. US (default) or EU. | String | If EU |
Returns
A new email message object based on the Mailgun credentials.
Example
local msg = core.email.new(<mailgun-key>, <mailgun-host>, <"US"|"EU">)