Application Center - Maplesoft

App Preview:

Sending Emails from the Maple Command Line

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




Sending Emails from Maple from the Maple Command Line

This application uses Maple's URL  package to send an email from the command-line. Using Maple's broader functionality, you could programatically construct an email (perhaps with the results of a computation) and send it to a user.

 

The code in this application communicates with Mailgun (http://mailgun.com), a free email delivery service with an web-based API. You'll need to replace certain parts with details from your own Mailgun account.

 

Note: Maplesoft have no affiliation with Mailgun.

 

Step 1:

Sign up for a free Mailgun account.

 

Step 2:

From your account, go to the Domains section - it should look like the screengrab below (account-specific information has been blanked).

 

Note down the API Base URL and the API key.

• 

The API Base URL looks like https://api.mailgun.net/v3/sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org.  

• 

the API Key looks like key-XXXXXXXXXXXXXXXXXXXXXXXXXX

 

The X's are account-specific.

 

Step 3:
Here, define APIBaseURL and APIKey as strings containing your own API Base URL and API Key. Also, define the recipient's email address, the email you want the recipient to reply to, the email subject and email body.

restart:
APIBaseURL := "https://api.mailgun.net/v3/sandboxXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org":
APIKey:="key-XXXXXXXXXXXXXXXXXXXXXXXX":

toEmail := "xxxxx@xxxxxx.com":
fromEmail:="First Last <FirstLast@Domain.com>":
subject:= "Email Subject Goes Here":
emailBody := "I'd rather have a bottle in front of me than a frontal lobotomy":

 

Step 4:
Run the following code

URL:-Post(cat(APIBaseURL,"/messages"), [
"from"=fromEmail,
"to"=toEmail,
"subject"=subject,
"text"= emailBody],
user="api",
password=APIKey);

 

If you've successfully sent the email, you should see something like this as the result of the code in Step 5 (account-specific information is blanked out))

 

You can also send HTML emails by replacing the "text" line with "html" = str, where str is a string containing the HTML code.