New SMTP handler
This commit is contained in:
parent
2a135f54b7
commit
1871572255
|
@ -135,16 +135,18 @@ $utopia->post('/v1/auth/register')
|
|||
->setParam('{{redirect}}', $redirect)
|
||||
;
|
||||
|
||||
$mail = $register->get('mailgun'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
$mail = $register->get('smtp'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
|
||||
$mail
|
||||
->addRecipient($email, $name)
|
||||
->setSubject(Locale::getText('auth.emails.confirm.title'))
|
||||
->setText(strip_tags($body->render()))
|
||||
->setHTML($body->render())
|
||||
;
|
||||
$mail->addAddress($email, $name);
|
||||
|
||||
if(!$mail->send()) {
|
||||
$mail->Subject = Locale::getText('auth.emails.confirm.title');
|
||||
$mail->Body = $body->render();
|
||||
$mail->AltBody = strip_tags($body->render());
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
}
|
||||
catch(Exception $error) {
|
||||
if($failure) {
|
||||
$response->redirect($failure);
|
||||
return;
|
||||
|
@ -273,16 +275,18 @@ $utopia->post('/v1/auth/register/confirm/resend')
|
|||
->setParam('{{redirect}}', $redirect)
|
||||
;
|
||||
|
||||
$mail = $register->get('mailgun'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
$mail = $register->get('smtp'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
|
||||
$mail
|
||||
->addRecipient($user->getAttribute('email'), $user->getAttribute('name'))
|
||||
->setSubject(Locale::getText('auth.emails.confirm.title'))
|
||||
->setText(strip_tags($body->render()))
|
||||
->setHTML($body->render())
|
||||
;
|
||||
$mail->addAddress($user->getAttribute('email'), $user->getAttribute('name'));
|
||||
|
||||
if(!$mail->send()) {
|
||||
$mail->Subject = Locale::getText('auth.emails.confirm.title');
|
||||
$mail->Body = $body->render();
|
||||
$mail->AltBody = strip_tags($body->render());
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
}
|
||||
catch(Exception $error) {
|
||||
throw new Exception('Problem sending mail: ' . $mail->getError(), 500);
|
||||
}
|
||||
|
||||
|
@ -503,16 +507,18 @@ $utopia->post('/v1/auth/recovery')
|
|||
->setParam('{{redirect}}', $redirect)
|
||||
;
|
||||
|
||||
$mail = $register->get('mailgun'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
$mail = $register->get('smtp'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
|
||||
$mail
|
||||
->addRecipient($profile->getAttribute('email', ''), $profile->getAttribute('name', ''))
|
||||
->setSubject(Locale::getText('auth.emails.recovery.title'))
|
||||
->setText(strip_tags($body->render()))
|
||||
->setHTML($body->render())
|
||||
;
|
||||
$mail->addAddress($profile->getAttribute('email', ''), $profile->getAttribute('name', ''));
|
||||
|
||||
if(!$mail->send()) {
|
||||
$mail->Subject = Locale::getText('auth.emails.recovery.title');
|
||||
$mail->Body = $body->render();
|
||||
$mail->AltBody = strip_tags($body->render());
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
}
|
||||
catch(Exception $error) {
|
||||
throw new Exception('Problem sending mail: ' . $mail->getError(), 500);
|
||||
}
|
||||
|
||||
|
|
|
@ -371,16 +371,18 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
->setParam('{{redirect}}', $redirect)
|
||||
;
|
||||
|
||||
$mail = $register->get('mailgun'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
$mail = $register->get('smtp'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
|
||||
$mail
|
||||
->addRecipient($email, $name)
|
||||
->setSubject(sprintf(Locale::getText('auth.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])))
|
||||
->setText(strip_tags($body->render()))
|
||||
->setHTML($body->render())
|
||||
;
|
||||
$mail->addAddress($email, $name);
|
||||
|
||||
if(!$mail->send()) {
|
||||
$mail->Subject = sprintf(Locale::getText('auth.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]']));
|
||||
$mail->Body = $body->render();
|
||||
$mail->AltBody = strip_tags($body->render());
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
}
|
||||
catch(Exception $error) {
|
||||
throw new Exception('Problem sending mail: ' . $mail->getError(), 500);
|
||||
}
|
||||
|
||||
|
@ -405,7 +407,7 @@ $utopia->post('/v1/teams/:teamId/memberships/:inviteId/resend')
|
|||
->param('inviteId', '', function () {return new UID();}, 'Invite unique ID.')
|
||||
->param('redirect', '', function () use ($project) {return new Host($project->getAttribute('clients', []));}, 'Reset page to redirect user back to your app from the invitation email.')
|
||||
->action(
|
||||
function($teamId, $inviteId, $redirect) use ($request, $response, $register, $project, $user, $audit, $projectDB)
|
||||
function($teamId, $inviteId, $redirect) use ($response, $register, $project, $user, $audit, $projectDB)
|
||||
{
|
||||
$membership = $projectDB->getDocument($inviteId);
|
||||
|
||||
|
@ -419,7 +421,7 @@ $utopia->post('/v1/teams/:teamId/memberships/:inviteId/resend')
|
|||
throw new Exception('Team not found', 404);
|
||||
}
|
||||
|
||||
if(empty($team->getUid()) !== $teamId) {
|
||||
if($team->getUid() !== $teamId) {
|
||||
throw new Exception('Team IDs don\'t match', 404);
|
||||
}
|
||||
|
||||
|
@ -450,19 +452,21 @@ $utopia->post('/v1/teams/:teamId/memberships/:inviteId/resend')
|
|||
->setParam('{{redirect}}', $redirect)
|
||||
;
|
||||
|
||||
$mail = $register->get('mailgun'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
$mail = $register->get('smtp'); /* @var $mail \MailgunLite\MailgunLite */
|
||||
|
||||
$mail
|
||||
->addRecipient($invitee->getAttribute('email'), $invitee->getAttribute('name'))
|
||||
->setSubject(sprintf(Locale::getText('auth.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]'])))
|
||||
->setText(strip_tags($body->render()))
|
||||
->setHTML($body->render())
|
||||
;
|
||||
$mail->addAddress($invitee->getAttribute('email'), $invitee->getAttribute('name'));
|
||||
|
||||
if(!$mail->send()) {
|
||||
$mail->Subject = sprintf(Locale::getText('auth.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]']));
|
||||
$mail->Body = $body->render();
|
||||
$mail->AltBody = strip_tags($body->render());
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
}
|
||||
catch(Exception $error) {
|
||||
throw new Exception('Problem sending mail: ' . $mail->getError(), 500);
|
||||
}
|
||||
|
||||
|
||||
$audit
|
||||
->setParam('userId', $user->getUid())
|
||||
->setParam('event', 'auth.invite.resend')
|
||||
|
@ -502,7 +506,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
throw new Exception('Invite not found', 404);
|
||||
}
|
||||
|
||||
if(empty($invite->getAttribute('teamId')->getUid()) !== $teamId) {
|
||||
if($invite->getAttribute('teamId')->getUid() !== $teamId) {
|
||||
throw new Exception('Team IDs don\'t match', 404);
|
||||
}
|
||||
|
||||
|
@ -621,7 +625,7 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
|||
throw new Exception('Invite not found', 404);
|
||||
}
|
||||
|
||||
if(empty($invite->getAttribute('teamId')->getUid()) !== $teamId) {
|
||||
if($invite->getAttribute('teamId') !== $teamId) {
|
||||
throw new Exception('Team IDs don\'t match', 404);
|
||||
}
|
||||
|
||||
|
|
30
app/init.php
30
app/init.php
|
@ -16,6 +16,7 @@ use Database\Adapter\MySQL as MySQLAdapter;
|
|||
use Database\Adapter\Redis as RedisAdapter;
|
||||
use Utopia\Locale\Locale;
|
||||
use Utopia\Registry\Registry;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
const APP_PROTOCOL = 'https';
|
||||
const APP_NAME = 'Appwrite';
|
||||
|
@ -112,17 +113,28 @@ $register->set('cache', function() use ($redisHost, $redisPort) { // Register ca
|
|||
$redis->connect($redisHost, $redisPort);
|
||||
return $redis;
|
||||
});
|
||||
$register->set('mailgun', function() use ($request, $domain) { // Register MailGun handler - TODO replace with SMTP connection
|
||||
$apiKey = $request->getServer('_APP_MAILGUN_KEY', '');
|
||||
$apiDomain = $request->getServer('_APP_MAILGUN_DOMAIN', '');
|
||||
$register->set('smtp', function() use ($request) {
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
$mailgun = new \MailgunLite\MailgunLite($apiKey, $apiDomain);
|
||||
$mail->isSMTP();
|
||||
|
||||
$mailgun
|
||||
->setFrom('team@appwrite.io', APP_NAME . ' Team') // Notice: Error when using '.test' domain to send emails with mailgun
|
||||
;
|
||||
$username = $request->getServer('_APP_SMTP_USERNAME', '');
|
||||
$password = $request->getServer('_APP_SMTP_PASSWORD', '');
|
||||
|
||||
return clone $mailgun;
|
||||
$mail->XMailer = 'Appwrite Mailer';
|
||||
$mail->Host = $request->getServer('_APP_SMTP_HOST', 'smtp');
|
||||
$mail->Port = $request->getServer('_APP_SMTP_PORT', 25);
|
||||
$mail->SMTPAuth = (!empty($username) && !empty($password));
|
||||
$mail->Username = $username;
|
||||
$mail->Password = $password;
|
||||
$mail->SMTPSecure = $request->getServer('_APP_SMTP_SECURE', '');
|
||||
|
||||
$mail->setFrom('team@appwrite.io', APP_NAME . ' Team');
|
||||
$mail->addReplyTo('team@appwrite.io', APP_NAME . ' Team');
|
||||
|
||||
$mail->isHTML(true);
|
||||
|
||||
return $mail;
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -208,4 +220,4 @@ if(APP_MODE_ADMIN === $mode) {
|
|||
}
|
||||
|
||||
// Set project mail
|
||||
$register->get('mailgun')->setFrom(APP_EMAIL_TEAM, sprintf(Locale::getText('auth.emails.team'), $project->getAttribute('name')));
|
||||
$register->get('smtp')->setFrom(APP_EMAIL_TEAM, sprintf(Locale::getText('auth.emails.team'), $project->getAttribute('name')));
|
|
@ -167,7 +167,7 @@ use Utopia\Locale\Locale;
|
|||
<ul data-ls-loop="members" data-ls-as="member" class="list">
|
||||
<li class="clear">
|
||||
<form class="pull-end"
|
||||
data-service="team.deleteTeamMembership"
|
||||
data-service="teams.deleteTeamMembership"
|
||||
data-scope="console"
|
||||
data-event="submit"
|
||||
data-success="alert,trigger"
|
||||
|
@ -188,13 +188,15 @@ use Utopia\Locale\Locale;
|
|||
data-service="teams.createTeamMembershipResend"
|
||||
data-scope="console"
|
||||
data-event="submit"
|
||||
data-loading="Resending invitation, please wait..."
|
||||
data-success="alert,trigger"
|
||||
data-success-param-alert-text="<?php echo Locale::getText('console.settings.section.members.invite.success'); ?>"
|
||||
data-success-param-trigger-events="membership-resend"
|
||||
data-failure="alert"
|
||||
data-failure-param-alert-text="<?php echo Locale::getText('console.settings.section.members.invite.failure'); ?>"
|
||||
data-failure-param-alert-classname="error">
|
||||
|
||||
|
||||
<input name="teamId" id="teamId" type="hidden" data-ls-bind="{{console-project.teamId}}">
|
||||
<input name="inviteId" id="inviteId" type="hidden" data-ls-bind="{{member.inviteId}}">
|
||||
<input name="redirect" type="hidden" data-ls-bind="https://{{env.DOMAIN}}/auth/join?project={{router.params.project}}" />
|
||||
|
||||
|
@ -221,6 +223,7 @@ use Utopia\Locale\Locale;
|
|||
data-service="teams.createTeamMembership"
|
||||
data-scope="console"
|
||||
data-event="submit"
|
||||
data-loading="Sending invitation, please wait..."
|
||||
data-success="alert,trigger,reset"
|
||||
data-success-param-alert-text="<?php echo Locale::getText('console.settings.section.members.invite.success'); ?>"
|
||||
data-success-param-trigger-events="membership-create,modal-close"
|
||||
|
|
|
@ -54,7 +54,8 @@
|
|||
"domnikl/statsd": "2.0.*",
|
||||
"influxdb/influxdb-php": "1.15.*",
|
||||
"bacon/bacon-qr-code": "2.0.0",
|
||||
"erusev/parsedown": "1.7.1"
|
||||
"erusev/parsedown": "1.7.1",
|
||||
"phpmailer/phpmailer": "6.0.7"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.0"
|
||||
|
|
85
composer.lock
generated
85
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2dfb6641e152a77d5562925e735890e0",
|
||||
"content-hash": "a82b974293d36c305d02a36c7e9ff420",
|
||||
"packages": [
|
||||
{
|
||||
"name": "appwrite/php-clamav",
|
||||
|
@ -1128,6 +1128,72 @@
|
|||
],
|
||||
"time": "2017-07-23 16:38:44"
|
||||
},
|
||||
{
|
||||
"name": "phpmailer/phpmailer",
|
||||
"version": "v6.0.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPMailer/PHPMailer.git",
|
||||
"reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/0c41a36d4508d470e376498c1c0c527aa36a2d59",
|
||||
"reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-ctype": "*",
|
||||
"ext-filter": "*",
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/annotations": "1.2.*",
|
||||
"friendsofphp/php-cs-fixer": "^2.2",
|
||||
"phpdocumentor/phpdocumentor": "2.*",
|
||||
"phpunit/phpunit": "^4.8 || ^5.7",
|
||||
"zendframework/zend-eventmanager": "3.0.*",
|
||||
"zendframework/zend-i18n": "2.7.3",
|
||||
"zendframework/zend-serializer": "2.7.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "Needed to send email in multibyte encoding charset",
|
||||
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
|
||||
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
|
||||
"psr/log": "For optional PSR-3 debug logging",
|
||||
"stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication",
|
||||
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PHPMailer\\PHPMailer\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jim Jagielski",
|
||||
"email": "jimjag@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Marcus Bointon",
|
||||
"email": "phpmailer@synchromedia.co.uk"
|
||||
},
|
||||
{
|
||||
"name": "Andy Prevost",
|
||||
"email": "codeworxtech@users.sourceforge.net"
|
||||
},
|
||||
{
|
||||
"name": "Brent R. Matzelle"
|
||||
}
|
||||
],
|
||||
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
|
||||
"time": "2019-02-01T15:04:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "piwik/device-detector",
|
||||
"version": "3.5.1",
|
||||
|
@ -1439,28 +1505,29 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "03dbdb9683a74379491d237504c1021ff3864b5b"
|
||||
"reference": "f07a7f388d9577265fa2bfafb7449505a1fcfc53"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/03dbdb9683a74379491d237504c1021ff3864b5b",
|
||||
"reference": "03dbdb9683a74379491d237504c1021ff3864b5b",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/f07a7f388d9577265fa2bfafb7449505a1fcfc53",
|
||||
"reference": "f07a7f388d9577265fa2bfafb7449505a1fcfc53",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": "^7.1.3",
|
||||
"symfony/polyfill-ctype": "^1.8",
|
||||
"symfony/polyfill-mbstring": "^1.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"psr/container": "^1.0",
|
||||
"symfony/debug": "^2.7",
|
||||
"symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0"
|
||||
"symfony/debug": "^3.4|^4.2",
|
||||
"symfony/mime": "^4.3",
|
||||
"symfony/phpunit-bridge": "^4.4@dev|^5.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.11-dev"
|
||||
"dev-master": "2.12-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -1498,7 +1565,7 @@
|
|||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"time": "2019-08-02 08:10:18"
|
||||
"time": "2019-08-08 16:07:29"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/abuse",
|
||||
|
|
|
@ -34,28 +34,36 @@ services:
|
|||
image: appwrite/mariadb:1.0.0 # fix issues when upgrading using: mysql_upgrade -u root -p
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
- MYSQL_ROOT_PASSWORD=password
|
||||
volumes:
|
||||
- ./storage/db:/var/lib/mysql:rw
|
||||
ports:
|
||||
- 3306:3306/tcp
|
||||
|
||||
redis:
|
||||
image: redis:5.0
|
||||
restart: unless-stopped
|
||||
smtp:
|
||||
image: appwrite/smtp:1.0.0
|
||||
environment:
|
||||
- MAILNAME=appwrite
|
||||
- RELAY_NETWORKS=:192.168.0.0/24:10.0.0.0/16
|
||||
ports:
|
||||
- "25:25"
|
||||
|
||||
clamav:
|
||||
image: appwrite/clamav:1.0.4
|
||||
restart: unless-stopped
|
||||
|
||||
redis:
|
||||
image: redis:5.0
|
||||
restart: unless-stopped
|
||||
|
||||
influxdb:
|
||||
image: influxdb:1.6
|
||||
volumes:
|
||||
- ./storage/influxdb:/var/lib/influxdb
|
||||
- ./storage/influxdb:/var/lib/influxdb
|
||||
ports:
|
||||
- "8086:8086"
|
||||
|
||||
- "8086:8086"
|
||||
|
||||
telegraf:
|
||||
image: appwrite/telegraf:1.0.0
|
||||
ports:
|
||||
- "8125:8125/udp"
|
||||
- "8125:8125/udp"
|
Loading…
Reference in a new issue