use custom smtp config
This commit is contained in:
parent
07010a5192
commit
20ff1b41a9
1 changed files with 38 additions and 12 deletions
|
@ -3,6 +3,7 @@
|
||||||
use Appwrite\Resque\Worker;
|
use Appwrite\Resque\Worker;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
require_once __DIR__ . '/../init.php';
|
require_once __DIR__ . '/../init.php';
|
||||||
|
|
||||||
|
@ -24,8 +25,10 @@ class MailsV1 extends Worker
|
||||||
{
|
{
|
||||||
global $register;
|
global $register;
|
||||||
|
|
||||||
|
$smtp = $this->args['smtp'];
|
||||||
|
|
||||||
if (empty(App::getEnv('_APP_SMTP_HOST'))) {
|
if (empty(App::getEnv('_APP_SMTP_HOST'))) {
|
||||||
Console::info('Skipped mail processing. No SMTP server hostname has been set.');
|
Console::info('Skipped mail processing. No SMTP configuration has been set.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,17 +40,7 @@ class MailsV1 extends Worker
|
||||||
$from = $this->args['from'];
|
$from = $this->args['from'];
|
||||||
|
|
||||||
/** @var \PHPMailer\PHPMailer\PHPMailer $mail */
|
/** @var \PHPMailer\PHPMailer\PHPMailer $mail */
|
||||||
$mail = $register->get('smtp');
|
$mail = empty($smtp) ? $register->get('smtp') : $this->getMailer($smtp);
|
||||||
|
|
||||||
// Set project mail
|
|
||||||
/*$register->get('smtp')
|
|
||||||
->setFrom(
|
|
||||||
App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
|
||||||
($project->getId() === 'console')
|
|
||||||
? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
|
||||||
: \sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
|
||||||
)
|
|
||||||
);*/
|
|
||||||
|
|
||||||
$mail->clearAddresses();
|
$mail->clearAddresses();
|
||||||
$mail->clearAllRecipients();
|
$mail->clearAllRecipients();
|
||||||
|
@ -58,6 +51,9 @@ class MailsV1 extends Worker
|
||||||
|
|
||||||
$mail->setFrom(App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM), (empty($from) ? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server')) : $from));
|
$mail->setFrom(App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM), (empty($from) ? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server')) : $from));
|
||||||
$mail->addAddress($recipient, $name);
|
$mail->addAddress($recipient, $name);
|
||||||
|
if (isset($smtp['replyTo'])) {
|
||||||
|
$mail->addReplyTo($smtp['replyTo']);
|
||||||
|
}
|
||||||
$mail->Subject = $subject;
|
$mail->Subject = $subject;
|
||||||
$mail->Body = $body;
|
$mail->Body = $body;
|
||||||
$mail->AltBody = \strip_tags($body);
|
$mail->AltBody = \strip_tags($body);
|
||||||
|
@ -69,6 +65,36 @@ class MailsV1 extends Worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getMailer(array $smtp): PHPMailer
|
||||||
|
{
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
|
||||||
|
$mail->isSMTP();
|
||||||
|
|
||||||
|
$username = $smtp['username'];
|
||||||
|
$password = $smtp['password'];
|
||||||
|
|
||||||
|
$mail->XMailer = 'Appwrite Mailer';
|
||||||
|
$mail->Host = $smtp['host'];
|
||||||
|
$mail->Port = $smtp['port'];
|
||||||
|
$mail->SMTPAuth = (!empty($username) && !empty($password));
|
||||||
|
$mail->Username = $username;
|
||||||
|
$mail->Password = $password;
|
||||||
|
$mail->SMTPSecure = $smtp['secure'] === 'tls';
|
||||||
|
$mail->SMTPAutoTLS = false;
|
||||||
|
$mail->CharSet = 'UTF-8';
|
||||||
|
|
||||||
|
$from = \urldecode($smtp['senderName'] ?? App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server'));
|
||||||
|
$email = $smtp['senderEmail'] ?? App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
|
||||||
|
|
||||||
|
$mail->setFrom($email, $from);
|
||||||
|
$mail->addReplyTo($email, $from);
|
||||||
|
|
||||||
|
$mail->isHTML(true);
|
||||||
|
|
||||||
|
return $mail;
|
||||||
|
}
|
||||||
|
|
||||||
public function shutdown(): void
|
public function shutdown(): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue