Skip to content

Commit

Permalink
Merge pull request #20 from sincilite/master
Browse files Browse the repository at this point in the history
Custom MAIL environment variables being overwritten when Outgoing mail is disabled.
  • Loading branch information
chadwcarlson committed Dec 12, 2023
2 parents 4975f32 + 2768ba6 commit 1e3312f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion platformsh-laravel-env.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function mapPlatformShRedisSession(string $relationshipName, Config $config) : v

function mapPlatformShMail(Config $config) : void
{
if (!isset($config->smtpHost)) {
if (empty($config->smtpHost)) {
return;
}

Expand Down
45 changes: 45 additions & 0 deletions tests/LaravelBridgeMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,49 @@ public function test_mail_gets_mapped() : void
$this->assertEquals('25', getenv('MAIL_PORT'));
$this->assertEquals('0', getenv('MAIL_ENCRYPTION'));
}

/**
* Test if the project has been instructed to disable Platform's own SMTP proxy
*
* @return void
*/
public function test_disabled_mail() : void
{
$smtpHost = 'smtp.external-service.com';
$smtpPort = '587';
$smtpMailer = 'sendmail';
$smtpEncyption = 'tls';

putenv('PLATFORM_APPLICATION_NAME=test');
putenv('PLATFORM_ENVIRONMENT=test');
putenv('PLATFORM_PROJECT_ENTROPY=test');
putenv('MAIL_HOST=' . $smtpHost);
putenv('MAIL_MAILER=' . $smtpMailer);
putenv('MAIL_PORT=' . $smtpPort);
putenv('MAIL_ENCRYPTION=' . $smtpEncyption);
$this->loadDummyRoutes();

/**
* https://support.platform.sh/hc/en-us/articles/12055076033810-Email-SMTP-sending-details
* There is mixed information on the value of PLATFORM_SMTP_HOST the above support ticket
* states When outgoing emails are off, the variable is empty
* Debugging on an instance shows it's set to false.
*
* These assertions test both senarios
*/
putenv(sprintf('PLATFORM_SMTP_HOST=%s', ''));
mapPlatformShEnvironment();
$this->assertEquals($smtpHost, getenv('MAIL_HOST'));
$this->assertEquals($smtpMailer, getenv('MAIL_MAILER'));
$this->assertEquals($smtpPort, getenv('MAIL_PORT'));
$this->assertEquals($smtpEncyption, getenv('MAIL_ENCRYPTION'));

putenv(sprintf('PLATFORM_SMTP_HOST=%s', false));
mapPlatformShEnvironment();
$this->assertEquals($smtpHost, getenv('MAIL_HOST'));
$this->assertEquals($smtpMailer, getenv('MAIL_MAILER'));
$this->assertEquals($smtpPort, getenv('MAIL_PORT'));
$this->assertEquals($smtpEncyption, getenv('MAIL_ENCRYPTION'));

}
}

0 comments on commit 1e3312f

Please sign in to comment.