APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

Mailer

Send application email through a unified, transport-independent APPNETOS Core service. Use the configured default mailbox or supply an explicit configuration for additional senders.

Architecture

The shared mailer controller creates messages, configurations and attachments. A transport adapter sends the message using PHPMailer. The active runtime context supplies the default mailbox from the effective configuration.

APPNETOS Mailer architecture and configuration flow

The default mailbox is configured in the global platform configuration and can be overridden by an application configuration. An application requiring additional mailboxes must create and manage their configurations explicitly.

Configuration resolution

Core\Config\Base loads platform/config/appnetos.php, followed by its environment-specific file, then the active application's base and environment-specific files. Values are merged recursively. Mailer settings are defined per runtime context (for example, contexts.app.mailer or contexts.admin.mailer).

Use a configuration overlay rather than editing generated configuration files. The mailer value can be null to disable the default mailbox. An explicitly constructed mailbox remains an application-level responsibility.

Configuration examples

Authenticated SMTP with TLS

'contexts' => [
    'app' => [
        'mailer' => [
            'name' => 'notifications',
            'transport' => 'smtp',
            'host' => 'smtp.example.com',
            'port' => 587,
            'email' => 'notifications@example.com',
            'user' => 'notifications@example.com',
            'pass' => getenv('APP_MAIL_PASSWORD') ?: '',
            'timeout' => 30,
            'sender_name' => 'Example Application',
            'smtp_auth' => true,
            'smtp_secure' => 'tls',
            'ignore_certificate' => false,
        ],
    ],
],

SMTP relay without authentication

'mailer' => [
    'transport' => 'smtp',
    'host' => 'mail-relay.internal',
    'port' => 25,
    'email' => 'system@example.com',
    'smtp_auth' => false,
    'smtp_secure' => null,
    'ignore_certificate' => false,
],

PHP mail and Sendmail

// PHP mail transport
'mailer' => [
    'transport' => 'mail',
    'email' => 'system@example.com',
],

// Sendmail transport
'mailer' => [
    'transport' => 'sendmail',
    'email' => 'system@example.com',
    'sendmail_path' => '/usr/sbin/sendmail',
],

These fragments belong inside the desired context section of a complete APPNETOS configuration array. The relay requires a trusted network. Keep certificate verification enabled in production.

Configuration reference

Key Description
name Optional configuration label
transport smtp, mail or sendmail
host SMTP hostname
port SMTP port, 1–65535
email Required sender email address
user SMTP authentication username
pass SMTP authentication password
timeout Positive timeout in seconds
sender_name Sender display name
smtp_auth Enable SMTP authentication
smtp_secure ssl, tls or null
ignore_certificate Disable certificate checks (not recommended)
sendmail_path Optional Sendmail binary path
header_content_id Optional content identifier for header
footer_content_id Optional content identifier for footer

SMTP requires host and port; credentials are required when smtp_auth is enabled. mail and sendmail require a sender address. The mailer configuration class performs additional validation when creating a configuration instance.

Send a message using the default mailbox

use Core\Mailer\Mailer;
use Core\Registry;

$mailer = Registry::get(Mailer::class);

if ($mailer->getUsable()) {
    $message = $mailer->createMessage(
        'Welcome to APPNETOS',
        '<p>Your account is ready.</p>',
        'Your account is ready.',
    );
    $message->addTo('recipient@example.com');
    $mailer->send($message);
}

The default configuration is resolved lazily and cached by the shared mailer controller. The message must contain a subject, HTML or plain-text content, and at least one recipient in To, CC or BCC.

Use a second mailbox

$otherMailbox = $mailer->createConfiguration([
    'transport' => 'smtp',
    'host' => 'smtp.example.com',
    'port' => 587,
    'email' => 'billing@example.com',
    'user' => 'billing@example.com',
    'pass' => getenv('BILLING_SMTP_PASSWORD') ?: '',
    'smtp_auth' => true,
    'smtp_secure' => 'tls',
]);

$message = $mailer->createMessage('Invoice', null, 'Your invoice is attached.');
$message->addTo('customer@example.com');
$message->addAttachment($mailer->createFileAttachment('/path/to/invoice.pdf'));
$mailer->send($message, $otherMailbox);

Applications may store additional mailbox settings in their own configuration or settings storage. The default Core mailer configuration does not automatically register multiple named accounts.

Attachments and delivery

File attachments, in-memory string attachments, inline content IDs, HTML and plain-text bodies, To/CC/BCC and Reply-To addresses are supported. Delivery is delegated to the selected transport; configuration or sending failures are reported through mailer exceptions.

Use php bin/appnetos cmd appnetos:mailer:test to test the configured mailbox. Avoid including credentials in logs or version-controlled files.

Public API Reference

Core\Mailer

Class & Registry

Class: Core\Mailer

Extends: Core\Mailer\Base

use Core\Mailer;
use Core\Registry;

$mailer = Registry::get(Mailer::class);
Method Description
__construct() Constructs the component
send() Public component operation
createConfiguration() Public component operation
createMessage() Public component operation
createFileAttachment() Public component operation
createStringAttachment() Public component operation
getConfiguration() Public component operation
getUsable() Public component operation
Core\Mailer\Configuration

Class & Registry

Class: Core\Mailer\Configuration

Extends: Core\Mailer\Configuration\Base

use Core\Mailer\Configuration;
use Core\Registry;

$configuration = Registry::get(Configuration::class);
Method Description
__construct() Constructs the component
init() Public component operation
getInitialized() Public component operation
getName() Public component operation
getTransport() Public component operation
getHost() Public component operation
getPort() Public component operation
getEmail() Public component operation
getUser() Public component operation
getPass() Public component operation
getTimeout() Public component operation
getSenderName() Public component operation
getSmtpAuth() Public component operation
getSmtpSecure() Public component operation
getIgnoreCertificate() Public component operation
getSendmailPath() Public component operation
getHeaderContentId() Public component operation
getFooterContentId() Public component operation
Core\Mailer\Message

Class & Registry

Class: Core\Mailer\Message

Extends: Core\Mailer\Message\Base

use Core\Mailer\Message;
use Core\Registry;

$message = Registry::get(Message::class);
Method description
__construct() Constructs the component
init() Public component operation
validate() Public component operation
getInitialized() Public component operation
getSubject() Public component operation
getHtml() Public component operation
getText() Public component operation
getTo() Public component operation
getCc() Public component operation
getBcc() Public component operation
getReplyTo() Public component operation
getAttachments() Public component operation
setSubject() Public component operation
setHtml() Public component operation
setText() Public component operation
addTo() Public component operation
addCc() Public component operation
addBcc() Public component operation
addReplyTo() Public component operation
addAttachment() Public component operation
Core\Mailer\Attachment

Class & Registry

Class: Core\Mailer\Attachment

Extends: Core\Mailer\Attachment\Base

use Core\Attachment;
use Core\Registry;

$attachment = Registry::get(Attachment::class);
Method Description
__construct() Constructs the component
initFile() Public component operation
initString() Public component operation
getInitialized() Public component operation
getPath() Public component operation
getContent() Public component operation
getName() Public component operation
getMime() Public component operation
getContentId() Public component operation
getStringAttachment() Public component operation
getInline() Public component operation
Core\Mailer\Transport

Class & Registry

Class: Core\Mailer\Transport

Extends: Core\Mailer\Transport\Base

use Core\Mailer\Transport;
use Core\Registry;

$transport = Registry::get(Transport::class);
Method Description
__construct() Constructs the component
send() Public component operation

Next Steps

Previous

Communication

Explore Communication

Next

Ajax

Explore Ajax