Sending E-Mails

The sendmail request allows to send arbitrary e-mails using the server's sendmail program.

Since this is effectively an open e-mail gateway, this must only be used in places where the end user can be identified. For anonymous contact forms, use submit requests.

Server setup

To send emails, you need to install a mail transfer agent (MTA) such as OpenSMTPD:

sudo apt install opensmtpd

Other supported MTAs are postfix and nullmailer.

You may also need to set up SPF/DKIM records for the envelope (Return-Path: ...) and sender (From: ...) addresses.

Account configuration

To use sendmail, an account must have the sendmail flag:

{"candy/paul": {"key": "...", "sendmail": {"envelope-from": "info@example.com"}, "...": null}, "candy/margrit": {"key": "...", "sendmail": true, "...": null}, "...": null}

Every end user should be given a separate account to track abuse.

JavaScript

Using Backend.js, a mail can be sent as follows:

const backend = new Backend('https://viereck.ch/backend');
const account = backend.account('your-account-id', '44705748... your-account-key');

const mail = `From: ali@some-domain.com
To: oskar@some-domain.com
Subject: Hello

This is a test email.`;

account.sendmail(mail, onDone, onError);

function onDone(request) {
	...
}

function onError(errorCode, request) {
	...
}
		

HTTP/REST Request

Request
POST /backend/sendmail
Account: ACCOUNT ID
Timestamp: TIMESTAMP
Signature: SIGNATURE
MAIL
Response

200 if the mail was sent

400 if the request was invalid

401 if the account ID or signature is missing or invalid

403 if the account is not allowed to use SVG to PDF

Account ID
Account key
MIME encoded e-mail

MAIL must be a properly encoded MIME message.