appwrite/src/Appwrite/Event/Mail.php

309 lines
5.7 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Event;
use Resque;
use Utopia\Database\Document;
class Mail extends Event
{
protected string $recipient = '';
protected string $from = '';
protected string $name = '';
protected string $subject = '';
protected string $body = '';
2023-03-12 02:12:09 +00:00
protected array $smtp = [];
public function __construct()
{
parent::__construct(Event::MAILS_QUEUE_NAME, Event::MAILS_CLASS_NAME);
}
2022-04-18 16:21:45 +00:00
/**
* Sets subject for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $subject
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns set team for the mail event.
*
* @return string
2022-04-18 16:21:45 +00:00
*/
public function getSubject(): string
{
return $this->subject;
}
2022-04-18 16:21:45 +00:00
/**
* Sets recipient for the mail event.
*
* @param string $recipient
* @return self
*/
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
*/
public function getRecipient(): string
{
return $this->recipient;
}
2022-04-18 16:21:45 +00:00
/**
* Sets from for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $from
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setFrom(string $from): self
{
$this->from = $from;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns from for mail event.
2022-04-18 16:21:45 +00:00
*
* @return string
*/
public function getFrom(): string
{
return $this->from;
}
2022-04-18 16:21:45 +00:00
/**
* Sets body for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $body
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns body for the mail event.
2022-04-18 16:21:45 +00:00
*
* @return string
*/
public function getBody(): string
{
return $this->body;
}
2022-04-18 16:21:45 +00:00
/**
* Sets name for the mail event.
*
* @param string $name
* @return self
*/
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
*/
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
*/
public function trigger(): string|bool
{
return Resque::enqueue($this->queue, $this->class, [
'from' => $this->from,
'recipient' => $this->recipient,
'name' => $this->name,
'subject' => $this->subject,
'body' => $this->body,
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
]);
}
2022-04-18 16:21:45 +00:00
}