Sending Emails With Sheerpower
Sheerpower includes an email facility for integrating
automated communication into applications. It can be used
for tasks such as distributing reports, sending system
alerts, or delivering invoices. This tutorial explains the
function's syntax and provides examples of its use in
business applications.
Whether you need to send plain text or richly formatted HTML emails,
attach documents, or handle authentication details automatically,
Sheerpower provides a straightforward and reliable way to do it.
This tutorial introduces the core syntax, shows how to use the
available parameters, and walks through practical examples that
demonstrate automated email communication in real applications.
Basic Syntax
email$ = 'mailto://' + sendto$ +
'?subject=' + subject$ +
'&mailfrom=' + mailfrom$ +
'&replyto=' + replyto$ +
'&friendlyname=' + friendlyname$ +
'&cc=' + cc$ +
'&server=' + servername$ +
'&username=' + username$ +
'&password=' + password$ +
'&port=2525' +
'&mime_type=html'
open file email_ch: name email$, access output
print #email_ch: 'Text of email.'
close #email_ch
1. Parameters Explained
| Parameter |
Description |
| sendto$ |
Email recipient |
| subject$ |
Subject line of the email |
| mailfrom$ |
The "from" email address |
| replyto$ |
The email address for replies |
| friendlyname$ |
Display name for the sender |
| cc$ |
Email addresses to copy |
| servername$ |
SMTP server address |
| username$ |
SMTP username (if required) |
| password$ |
SMTP password (if required) |
| port |
If using a non-standard SMTP port |
| mime_type=html |
Specifies HTML email format |
2. Example
This example demonstrates sending an email with user input:
<
mailform$ = '<form>' +
'From: <input name="from"><br>' +
'Reply To: <input name="reply"><br>' +
'Text: <textarea name="body"></textarea>' +
'<input type="submit">' +
'</form>'
line input dialogbox mailform$: data$
email$ = 'mailto://' + sendto$ + '?subject=' + subject$ +
'&mailfrom=' + mailfrom$ + '&replyto=' + replyto$
open out_ch: name email$, access output
print #out_ch: 'Hello World'
close #out_ch
3. Best Practices
- Use a local or commercial SMTP server to minimize delays.
- Include authentication credentials if required by the SMTP server.
Note: For highest
reliability, ensure the SMTP server is
on the same server as Sheerpower, on
the same LAN, or on a commercially
available SMTP high-availability
service, such as
https://www.authsmtp.com/.
Problem: Sending email
can block execution if the SMTP server
responds slowly.
Solution: Sheerpower
routes all outbound email through a
dedicated background thread inside the
virtual machine.
Efficiency: This keeps
SMTP activity independent of your main
program, preventing stalls and keeping
logic responsive.
Takeaway: Your program
continues running smoothly while email
delivery proceeds in parallel.
4. When the Email Is Sent, and When It Cannot Be
close #email_ch hands the email over and the program goes on at once: the email is sent in the
background. When the server cannot take it right now (it is busy, down, or asks to try later), it is tried
again every minute, up to 100 times. When the program ends, Sheerpower waits up to 30 seconds for the emails
still due to go.
An email that cannot be sent -- the server refused it for good, or its last try failed too -- is reported on
the console, in bold red (on stderr under /headless):
?? Email to [email protected] not sent: smtp.example.com: [email protected]: 550 no such user here
To know in the program whether the email went, add
&wait: close then tries the email once, right away, for up to about a minute.
A server that refuses it for good makes close raise EMAIL_NOT_SENT ("Email not
sent"), with the server's reply in _string$. A server that can only take it later lets
close go on, and the email is tried again in the background.
email$ = 'mailto://
[email protected]?subject=Test' +
'
[email protected]&server=example.com&wait'
open file email_ch: name email$, access output
print #email_ch: 'Hello'
when exception in
close #email_ch
use
print extext$; ': '; _string$
end when
Output (example.com publishes that it takes no email):
Email not sent: example.com: the domain takes no mail (a null MX record)
5. Mail Servers and Encryption
- Which server. When
server= names a domain that publishes its mail servers (MX
records), the email goes to them, the most preferred first; otherwise to the name itself. So
server=smtp.provider.com works as it always has, and
server=company.com&port=25 delivers straight to company.com's own mail servers.
- Port 465 is encrypted (TLS) from the first byte,
and the server's certificate is checked: an email to a server whose certificate is not valid is not
sent.
- Any other port (25, 587 ...): when the server offers encryption (STARTTLS) it is used; when it
offers none, or the encryption cannot be set up, the email is sent unencrypted, as it always was. The
certificate is not checked on these ports, so an in-house server with a certificate of its own works.
- On Windows the encryption needs two files beside
sp4gl.exe, which the installer puts
there: libcrypto-3-x64.dll and libssl-3-x64.dll. Without them every email is
sent unencrypted, and port 465 cannot be used. On Linux the encryption is built in.
Business Application Examples
Sheerpower's email facility enables automation for various business tasks. Below are
eight examples demonstrating its use in business applications, including overnight
processes and report generation.
-
Automated Report Distribution
Generate and send daily reports to stakeholders:
email$ = 'mailto://
[email protected]?subject=Daily Sales Report' +
'
[email protected]&mime_type=html'
open file email_ch: name email$, access output
print #email_ch: '<h1>Daily Sales Report</h1>'
print #email_ch: '<p>Total Sales: $50,000</p>'
close #email_ch
-
Invoice Delivery
Send invoices to customers after processing orders:
email$ = 'mailto://
[email protected]?subject=Your Invoice' +
'
[email protected]&attach=invoice123.pdf'
open file email_ch: name email$, access output
print #email_ch: 'Dear Customer,'
print #email_ch: 'Please find your invoice attached.'
close #email_ch
-
Server Monitoring Alerts
Send alerts when server metrics exceed thresholds:
email$ = 'mailto://
[email protected]?subject=Server Alert' +
'
[email protected]'
open file email_ch: name email$, access output
print #email_ch: 'CPU usage has exceeded 90%. Immediate attention required.'
close #email_ch
-
Employee Timesheet Reminders
Send weekly reminders to employees to complete timesheets:
email$ = 'mailto://
[email protected]?subject=Timesheet Reminder' +
'
[email protected]'
open file email_ch: name email$, access output
print #email_ch: 'Please complete your timesheet by Friday, 5 PM.'
close #email_ch
-
Customer Feedback Requests
Request feedback from customers after service completion:
email$ = 'mailto://
[email protected]?subject=We Value Your Feedback' +
'
[email protected]&mime_type=html'
open file email_ch: name email$, access output
print #email_ch: '<h2>Your Feedback is Important</h2>'
print #email_ch: '<p>Please click <a href="https://survey.com">here</a> to ' +
'give your feedback.</p>'
close #email_ch
-
System Backup Completion Notifications
Notify administrators of successful backup completions:
email$ = 'mailto://
[email protected]?subject=Backup Completed' +
'
[email protected]&attach=backup_log.txt'
open file email_ch: name email$, access output
print #email_ch: 'The nightly backup completed successfully.'
close #email_ch
-
Sales Order Notifications
Inform the sales team of new orders placed:
email$ = 'mailto://
[email protected]?subject=New Order Received' +
'
[email protected]'
open file email_ch: name email$, access output
print #email_ch: 'Order #12345 has been placed by Customer XYZ.'
print #email_ch: 'Total Amount: $250.00.'
close #email_ch
-
Late Payment Notices
Send automated reminders for overdue invoices:
email$ = 'mailto://
[email protected]?subject=Payment Overdue' +
'
[email protected]'
open file email_ch: name email$, access output
print #email_ch: 'Dear Customer,'
print #email_ch: 'Our records show that invoice #98765 is overdue.'
print #email_ch: 'Please make payment at your earliest convenience.'
close #email_ch
Summary: Email Facility
Sheerpower's email facility provides a straightforward solution
for automating email-based tasks in business applications. By constructing
email URLs with the mailto:// scheme and using SMTP
servers, developers can send plain text or HTML emails, attach files, and
include advanced configurations such as authentication and CC/BCC recipients.
This tutorial highlighted several practical applications:
- Automated Report Distribution: Send daily or periodic reports.
- Invoice Delivery: Email invoices with attachments.
- Server Monitoring Alerts: Notify administrators of critical events.
- Employee Reminders: Automate timesheet and task notifications.
- Customer Feedback Requests: Collect feedback via email surveys.
- Backup Notifications: Alert on backup completion or failure.
- Sales Order Updates: Inform teams of new orders.
- Late Payment Notices: Remind customers about overdue invoices.
By using optional parameters like mime_type,
username, and password, emails can be customized to
meet various business needs securely. Best practices, such as utilizing a
local SMTP server for critical messages, enhance
reliability and efficiency.
With its simplicity and flexibility, Sheerpower's email facility is an
essential tool for automating communication in modern business environments.
(Show/Hide Sheerpower Email Facility Takeaways)
Sheerpower Email Facility Takeaways
- Use the
mailto:// URI scheme to construct outgoing
email URLs with parameters for subject, sender, server, and more.
- Open a file channel using the email URI, print email contents to
the channel, then close it to send the email.
- HTML emails are supported using
&mime_type=html.
- Attachments can be added using the
&attach=filename
parameter.
close returns at once and the email is sent in the background, tried again every minute
when the server cannot take it yet; an email that cannot be sent is reported on the console.
- Add
&wait to have close raise EMAIL_NOT_SENT when the server
refuses the email for good.
- Port 465 is always encrypted; other ports are encrypted whenever the server offers it.
- Common parameters include:
sendto$ — recipient
mailfrom$ — sender address
replyto$ — reply address
servername$, username$,
password$ — SMTP authentication
- Forms and user input can dynamically populate email fields.
- Recommended: Use a LAN-based or commercial SMTP service for
reliability and delivery assurance.
- Practical use cases include:
- Daily report distribution
- Automated invoice delivery
- System alert notifications
- Employee reminders and timesheets
- Customer feedback requests
- Backup success/failure reports
- Sales order confirmations
- Late payment reminders
- Sending email requires no external libraries—just open, print, and
close the email file channel.