2022-04-13 12:39:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
|
|
use Resque;
|
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
|
|
class Mail extends Event
|
|
|
|
|
{
|
|
|
|
|
protected string $recipient = '';
|
2022-12-14 06:23:14 +00:00
|
|
|
protected string $from = '';
|
2022-04-13 12:39:31 +00:00
|
|
|
protected string $name = '';
|
2022-12-14 06:23:14 +00:00
|
|
|
protected string $subject = '';
|
|
|
|
|
protected string $body = '';
|
2023-03-12 02:12:09 +00:00
|
|
|
protected array $smtp = [];
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct(Event::MAILS_QUEUE_NAME, Event::MAILS_CLASS_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets subject for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $subject
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setSubject(string $subject): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->subject = $subject;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set team for the mail event.
|
|
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @return string
|
2022-04-18 16:21:45 +00:00
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getSubject(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->subject;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Sets recipient for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $recipient
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function setRecipient(string $recipient): self
|
|
|
|
|
{
|
|
|
|
|
$this->recipient = $recipient;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set recipient for mail event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function getRecipient(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->recipient;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets from for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $from
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setFrom(string $from): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->from = $from;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Returns from for mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getFrom(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->from;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets body for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $body
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setBody(string $body): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->body = $body;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Returns body for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getBody(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->body;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Sets name for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function setName(string $name): self
|
|
|
|
|
{
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set name for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function getName(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-12 02:12:09 +00:00
|
|
|
/**
|
2023-03-13 06:23:23 +00:00
|
|
|
* Set SMTP Host
|
2023-03-12 02:12:09 +00:00
|
|
|
*
|
2023-03-13 06:23:23 +00:00
|
|
|
* @param string $host
|
2023-03-12 02:12:09 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-03-13 06:23:23 +00:00
|
|
|
public function setSmtpHost(string $host): self
|
2023-03-12 02:12:09 +00:00
|
|
|
{
|
2023-03-13 06:23:23 +00:00
|
|
|
$this->smtp['host'] = $host;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP port
|
|
|
|
|
*
|
|
|
|
|
* @param int port
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpPort(int $port): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['port'] = $port;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP username
|
|
|
|
|
*
|
|
|
|
|
* @param string $username
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpUsername(string $username): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['username'];
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP password
|
|
|
|
|
*
|
|
|
|
|
* @param string $password
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpPassword(string $password): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['password'];
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP sender name
|
|
|
|
|
*
|
|
|
|
|
* @param string $senderName
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpSenderName(string $senderName): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['senderName'] = $senderName;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP sender email
|
|
|
|
|
*
|
|
|
|
|
* @param string $senderEmail
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpSenderEmail(string $senderEmail): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['senderEmail'] = $senderEmail;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set SMTP reply to
|
|
|
|
|
*
|
|
|
|
|
* @param string $replyTo
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtpReplyTo(string $replyTo): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp['replyTo'] = $replyTo;
|
2023-03-12 02:12:09 +00:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-03-13 06:23:23 +00:00
|
|
|
public function getSmtpHost(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['host'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP port
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpPort(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['port'] ?? 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP username
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpUsername(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['username'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP password
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpPassword(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['password'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP sender name
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpSenderName(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['senderName'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP sender email
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpSenderEmail(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp['senderEmail'] ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP reply to
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtpReplyTo(): string
|
2023-03-12 02:12:09 +00:00
|
|
|
{
|
2023-03-13 06:23:23 +00:00
|
|
|
return $this->smtp['replyTo'] ?? '';
|
2023-03-12 02:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Executes the event and sends it to the mails worker.
|
|
|
|
|
*
|
|
|
|
|
* @return string|bool
|
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function trigger(): string|bool
|
|
|
|
|
{
|
|
|
|
|
return Resque::enqueue($this->queue, $this->class, [
|
2022-12-14 06:23:14 +00:00
|
|
|
'from' => $this->from,
|
2022-04-13 12:39:31 +00:00
|
|
|
'recipient' => $this->recipient,
|
|
|
|
|
'name' => $this->name,
|
2022-12-14 06:23:14 +00:00
|
|
|
'subject' => $this->subject,
|
|
|
|
|
'body' => $this->body,
|
2022-04-13 12:39:31 +00:00
|
|
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
|
|
|
|
]);
|
|
|
|
|
}
|
2022-04-18 16:21:45 +00:00
|
|
|
}
|