Nextcloud PHP API (stable18)

IMailer

Class IMailer provides some basic functions to create a mail message that can be used in combination with \OC\Mail\Message.

Example usage:

$mailer = \OC::$server->getMailer();
$message = $mailer->createMessage();
$message->setSubject('Your Subject');
$message->setFrom(['cloud@domain.org' => 'Nextcloud Notifier']);
$message->setTo(['recipient@domain.org' => 'Recipient']);
$message->setPlainBody('The message text');
$message->setHtmlBody('The <strong>message</strong> text');
$mailer->send($message);

This message can then be passed to send() of \OC\Mail\Mailer

Tags
since
8.1.0

Table of Contents

createAttachment()  : IAttachment
createAttachmentFromPath()  : IAttachment
createEMailTemplate()  : IEMailTemplate
Creates a new email template object
createMessage()  : IMessage
Creates a new message object that can be passed to send()
send()  : string[]
Send the specified message. Also sets the from address to the value defined in config.php if no-one has been passed.
validateMailAddress()  : bool
Checks if an e-mail address is valid

Methods

createAttachment()

public createAttachment([string|null $data = null ][, string|null $filename = null ][, string|null $contentType = null ]) : IAttachment
Parameters
$data : string|null = null
$filename : string|null = null
$contentType : string|null = null
Tags
since
13.0.0
Return values
IAttachment

createAttachmentFromPath()

public createAttachmentFromPath(string $path[, string|null $contentType = null ]) : IAttachment
Parameters
$path : string
$contentType : string|null = null
Tags
since
13.0.0
Return values
IAttachment

createEMailTemplate()

Creates a new email template object

public createEMailTemplate(string $emailId[, array $data = [] ]) : IEMailTemplate
Parameters
$emailId : string
$data : array = []
Tags
since
12.0.0

Parameters added in 12.0.3

Return values
IEMailTemplate

createMessage()

Creates a new message object that can be passed to send()

public createMessage() : IMessage
Tags
since
8.1.0
Return values
IMessage

send()

Send the specified message. Also sets the from address to the value defined in config.php if no-one has been passed.

public send(IMessage $message) : string[]
Parameters
$message : IMessage

Message to send

Tags
throws
Exception

In case it was not possible to send the message. (for example if an invalid mail address has been supplied.)

since
8.1.0
Return values
string[]

Array with failed recipients. Be aware that this depends on the used mail backend and therefore should be considered

validateMailAddress()

Checks if an e-mail address is valid

public validateMailAddress(string $email) : bool
Parameters
$email : string

Email address to be validated

Tags
since
8.1.0
Return values
bool

True if the mail address is valid, false otherwise

Search results