Mailer

class OC\Mail\Mailer
Class Mailer 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(array('cloud@domain.org‘ => ‘ownCloud Notifier’));
$message->setTo(array('recipient@domain.org‘ => ‘Recipient’));
$message->setBody(‘The message text’, ‘text/html’);
$mailer->send($message);

This message can then be passed to send() of \OC\Mail\Mailer
Source:lib/private/Mail/Mailer.php#72
Implements:OCP\Mail\IMailer

Properties

Methods

public OC\Mail\Mailer::__construct($config, $logger, $defaults, $urlGenerator, $l10n, $dispatcher, $l10nFactory)
Source:

lib/private/Mail/Mailer.php#98

Parameters:
public OC\Mail\Mailer::createMessage()
Creates a new message object that can be passed to send()
Source:lib/private/Mail/Mailer.php#119
Returns:\OCP\Mail\IMessage
public OC\Mail\Mailer::createAttachment($data=null, $filename=null, $contentType=null)
Source:

lib/private/Mail/Mailer.php#131

Parameters:
  • $data (string | null)
  • $filename (string | null)
  • $contentType (string | null)
Returns:

\OCP\Mail\IAttachment

Since:

13.0.0

public OC\Mail\Mailer::createAttachmentFromPath($path, $contentType=null)
Source:

lib/private/Mail/Mailer.php#141

Parameters:
  • $path (string)
  • $contentType (string | null)
Returns:

\OCP\Mail\IAttachment

Since:

13.0.0

public OC\Mail\Mailer::createEMailTemplate($emailId, $data=[])
Creates a new email template object
Source:

lib/private/Mail/Mailer.php#153

Parameters:
  • $emailId (string)
  • $data (array)
Returns:

\OCP\Mail\IEMailTemplate

Since:

12.0.0

public OC\Mail\Mailer::send($message)
Send the specified message. Also sets the from address to the value defined in config.php
if no-one has been passed.
Source:

lib/private/Mail/Mailer.php#185

Parameters:
Returns:

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

Throws:

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

public OC\Mail\Mailer::validateMailAddress($email)
Checks if an e-mail address is valid
Source:

lib/private/Mail/Mailer.php#223

Parameters:
  • $email (string) Email address to be validated
Returns:

bool True if the mail address is valid, false otherwise

protected OC\Mail\Mailer::convertEmail($email)
SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
FIXME: Remove this once SwiftMailer supports IDN
Source:

lib/private/Mail/Mailer.php#242

Parameters:
  • $email (string)
Returns:

string Converted mail address if `idn_to_ascii` exists

protected OC\Mail\Mailer::getInstance()
Source:lib/private/Mail/Mailer.php#252
protected OC\Mail\Mailer::getSmtpInstance()
Returns the SMTP transport
Source:lib/private/Mail/Mailer.php#277
Returns:\Swift_SmtpTransport
protected OC\Mail\Mailer::getSendMailInstance()
Returns the sendmail transport
Source:lib/private/Mail/Mailer.php#304
Returns:\Swift_SendmailTransport