Is the time inconvenient? Did you send your email too early? Delaying emails can be useful in many situations: whether it's to give yourself time to check something or to manage your own workload effectively - timing can be crucial. Here are three ways you can delay sending emails and optimize your own communication.
Outlook
Microsoft Outlook offers a built-in feature that allows you to delay emails. To do this, use the feature "Options > Delay Delivery":

The big disadvantage of this solution is that (even in Exchange environments) Outlook has to run on the client side at the time of sending.
Gmail offers a slightly better solution here. To do this, click on "Schedule Sending" before sending an email.:

You can also "undo" emails that have already been sent within 30 seconds. To do this, first set the relevant setting under "View all settings":

If you now send an email, you can undo it at the bottom left within this time period:

Boomerang
There are paid service providers such as Boomerang for Outlook that offer reminders or automated follow-ups as well as delayed email sending:

The disadvantage here is that the emails end up on third-party servers and there is a charge for using them.
PHP
Reason enough to build something yourself: With the help of a small PHP script you can also achieve what you want. First we create a folder structure in our mailbox:

This indicates the desired sending time. The workflow now consists of saving the composed email as a draft instead of sending it and moving it to the relevant folder. We then install all the required PHP packages:
composer require php-imap/php-imap phpmailer/phpmailer vlucas/phpdotenv
Finally, we create a .env
File with access data and settings:
HOST_SMTP="xxx"
PORT_SMTP=465
HOST_IMAP="xxx"
PORT_IMAP=993
USERNAME="foo@bar.com"
PASSWORD="xxx"
ENCRYPTION="ssl"
FROM_ADDRESS="foo@bar.com"
FROM_NAME="Foo Bar"
FOLDER_INBOX="INBOX/DELAY"
FOLDER_OUTBOX="Gesendete Elemente"
PHP_EXECUTABLE="/usr/bin/php"
The following PHP script then does the rest:
<?php
require_once __DIR__ . '/vendor/autoload.php';
class MailDelay
{
private \PhpImap\Mailbox $mailbox;
private array $folders;
public function init(): void
{
$this->loadEnvironmentVariables();
$this->initMailbox();
$this->initFolders();
$this->processFolders();
}
private function loadEnvironmentVariables(): void
{
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
}
private function initMailbox(): void
{
$this->mailbox = new \PhpImap\Mailbox(
'{' . $_SERVER['HOST_IMAP'] . ':' . $_SERVER['PORT_IMAP'] . '/imap/ssl}' . $_SERVER['FOLDER_INBOX'],
$_SERVER['USERNAME'],
$_SERVER['PASSWORD'],
sys_get_temp_dir(),
'UTF-8'
);
}
private function initFolders(): void
{
$this->folders = [];
$folders = $this->mailbox->getMailboxes('*');
foreach ($folders as $folder) {
if ($folder['shortpath'] === $_SERVER['FOLDER_INBOX']) {
continue;
}
$this->folders[] = (object) $folder;
}
}
private function processFolders(): void
{
foreach ($this->folders as $folder) {
$this->mailbox->switchMailbox($folder->fullpath);
$mailIds = $this->mailbox->searchMailbox('ALL');
foreach ($mailIds as $mailId) {
$preparedMail = $this->prepareMailData($mailId, $folder->shortpath);
if (
$preparedMail->subject !== 'Dies ist Plain Text' &&
strtotime($preparedMail->time_to_send) > strtotime('now')
) {
continue;
}
try {
$this->sendMail($preparedMail);
echo 'Successfully sent mail #' . $preparedMail->id . '.' . PHP_EOL;
} catch (\Exception $e) {
echo 'Error in sending mail #' . $preparedMail->id . ': ' . $e->getMessage() . PHP_EOL;
}
}
}
echo 'All mails have been processed.' . PHP_EOL;
}
private function prepareMailData(int $id, string $folder): object
{
$mail = $this->mailbox->getMail($id, false); // don't mark as unread
return (object) [
'id' => (string) $mail->id,
'to' => $this->formatEmailAddresses($mail->to),
'cc' => $this->formatEmailAddresses($mail->cc),
'bcc' => $this->formatEmailAddresses($mail->bcc),
'subject' => (string) $mail->subject,
'content_html' => $this->convertEncoding($mail->textHtml),
'content_plain' => $this->convertEncoding($mail->textPlain),
'attachments' => $this->determineAttachments($mail->getAttachments()),
'time_to_send' => $this->determineTimeToSend(explode('/', $folder)[2], $mail->date)
];
}
private function formatEmailAddresses(?array $addresses): ?array
{
if (empty($addresses)) {
return null;
}
return array_map(
function ($key, $value) {
return [
'email' => $key,
'name' => $key === $value ? null : str_replace(' (' . $key . ')', '', $value)
];
},
array_keys($addresses),
$addresses
);
}
private function convertEncoding(string $text): string
{
return mb_detect_encoding($text, 'UTF-8, ISO-8859-1') !== 'UTF-8'
? \UConverter::transcode($text, 'UTF8', 'ISO-8859-1')
: $text;
}
private function determineAttachments(array $attachmentsImap): array
{
$attachments = [];
if (!empty($attachmentsImap)) {
foreach ($attachmentsImap as $attachment) {
$attachments[] = [
'name' => $attachment->name,
'file' => $attachment->filePath,
'disposition' => $attachment->disposition,
'inline_id' => $attachment->contentId
];
}
}
return $attachments;
}
private function determineTimeToSend(string $delayTime, string $date): ?string
{
$timeToSend = null;
if ($delayTime === 'THIS EVENING') {
$timeToSend = date('Y-m-d', strtotime($date)) . ' 18:00:00';
} elseif ($delayTime === 'THIS NIGHT') {
$timeToSend =
date('Y-m-d', strtotime($date . (date('H', strtotime($date)) >= 4 ? ' + 1 day' : ''))) . ' 03:42:00';
} elseif ($delayTime === 'NEXT MORNING') {
$timeToSend =
date('Y-m-d', strtotime($date . (date('H', strtotime($date)) >= 9 ? ' + 1 day' : ''))) . ' 09:00:00';
} elseif ($delayTime === 'NEXT WEEK') {
$date = new \DateTime(date('Y-m-d', strtotime($date)));
$date->modify('next monday');
$timeToSend = $date->format('Y-m-d') . ' 09:00:00';
}
return $timeToSend;
}
private function sendMail(object $preparedMail): void
{
$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
$mail->Host = $_SERVER['HOST_SMTP'];
$mail->Port = $_SERVER['PORT_SMTP'];
$mail->Username = $_SERVER['USERNAME'];
$mail->Password = $_SERVER['PASSWORD'];
$mail->SMTPSecure = $_SERVER['ENCRYPTION'];
$mail->setFrom($_SERVER['FROM_ADDRESS'], $_SERVER['FROM_NAME']);
$mail->SMTPAuth = true;
$mail->SMTPOptions = [
'tls' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true],
'ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]
];
$mail->CharSet = 'utf-8';
$this->addRecipients($mail, $preparedMail->to, 'addAddress');
$this->addRecipients($mail, $preparedMail->cc, 'addCC');
$this->addRecipients($mail, $preparedMail->bcc, 'addBCC');
$mail->isHTML(!empty($preparedMail->content_html));
$mail->Subject = $preparedMail->subject;
if (!empty($preparedMail->content_html)) {
$mail->Body = $preparedMail->content_html;
$mail->AltBody = !empty($preparedMail->content_plain)
? $preparedMail->content_plain
: strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\r\n", $preparedMail->content_html));
} else {
$mail->Body = $preparedMail->content_plain;
}
$this->addAttachments($mail, $preparedMail->attachments);
$mail->send();
$this->mailbox->moveMail($preparedMail->id, $_SERVER['FOLDER_OUTBOX']);
}
private function addRecipients(\PHPMailer\PHPMailer\PHPMailer $mail, ?array $recipients, string $method): void
{
if (!empty($recipients)) {
foreach ($recipients as $recipient) {
$mail->$method($recipient['email'], $recipient['name']);
}
}
}
private function addAttachments(\PHPMailer\PHPMailer\PHPMailer $mail, array $attachments): void
{
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
if (!empty($attachment['file']) && !empty($attachment['name']) && file_exists($attachment['file'])) {
if ($attachment['disposition'] === 'attachment') {
$mail->addAttachment($attachment['file'], $attachment['name']);
} elseif ($attachment['disposition'] === 'inline') {
$mail->AddEmbeddedImage(
$attachment['file'],
$attachment['inline_id'],
$attachment['name'],
'base64',
'image/png'
);
}
}
}
}
}
}
$md = new MailDelay();
$md->init();
To make this script run repeatedly, we create a Bash file:
#!/usr/bin/env bash
source $(dirname "$0")/.env
"$PHP_EXECUTABLE" $(dirname "$0")/maildelay.php
We then run this script every 10 minutes via cronjob:
*/10 * * * * /path/to/maildelay/maildelay.sh 2>&1
This solution is flexible, data protection-friendly and free. It works with any (IMAP-compatible) account. But regardless of whether you use the integrated function in Outlook or Gmail, rely on advanced tools such as Boomerang or implement an individual solution - sending emails at a later time is a valuable tool for increasing your productivity.