Skip to content

Commit 1e3312f

Browse files
authored
Merge pull request #20 from sincilite/master
Custom MAIL environment variables being overwritten when Outgoing mail is disabled.
2 parents 4975f32 + 2768ba6 commit 1e3312f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

platformsh-laravel-env.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function mapPlatformShRedisSession(string $relationshipName, Config $config) : v
156156

157157
function mapPlatformShMail(Config $config) : void
158158
{
159-
if (!isset($config->smtpHost)) {
159+
if (empty($config->smtpHost)) {
160160
return;
161161
}
162162

tests/LaravelBridgeMailTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,49 @@ public function test_mail_gets_mapped() : void
4545
$this->assertEquals('25', getenv('MAIL_PORT'));
4646
$this->assertEquals('0', getenv('MAIL_ENCRYPTION'));
4747
}
48+
49+
/**
50+
* Test if the project has been instructed to disable Platform's own SMTP proxy
51+
*
52+
* @return void
53+
*/
54+
public function test_disabled_mail() : void
55+
{
56+
$smtpHost = 'smtp.external-service.com';
57+
$smtpPort = '587';
58+
$smtpMailer = 'sendmail';
59+
$smtpEncyption = 'tls';
60+
61+
putenv('PLATFORM_APPLICATION_NAME=test');
62+
putenv('PLATFORM_ENVIRONMENT=test');
63+
putenv('PLATFORM_PROJECT_ENTROPY=test');
64+
putenv('MAIL_HOST=' . $smtpHost);
65+
putenv('MAIL_MAILER=' . $smtpMailer);
66+
putenv('MAIL_PORT=' . $smtpPort);
67+
putenv('MAIL_ENCRYPTION=' . $smtpEncyption);
68+
$this->loadDummyRoutes();
69+
70+
/**
71+
* https://support.platform.sh/hc/en-us/articles/12055076033810-Email-SMTP-sending-details
72+
* There is mixed information on the value of PLATFORM_SMTP_HOST the above support ticket
73+
* states When outgoing emails are off, the variable is empty
74+
* Debugging on an instance shows it's set to false.
75+
*
76+
* These assertions test both senarios
77+
*/
78+
putenv(sprintf('PLATFORM_SMTP_HOST=%s', ''));
79+
mapPlatformShEnvironment();
80+
$this->assertEquals($smtpHost, getenv('MAIL_HOST'));
81+
$this->assertEquals($smtpMailer, getenv('MAIL_MAILER'));
82+
$this->assertEquals($smtpPort, getenv('MAIL_PORT'));
83+
$this->assertEquals($smtpEncyption, getenv('MAIL_ENCRYPTION'));
84+
85+
putenv(sprintf('PLATFORM_SMTP_HOST=%s', false));
86+
mapPlatformShEnvironment();
87+
$this->assertEquals($smtpHost, getenv('MAIL_HOST'));
88+
$this->assertEquals($smtpMailer, getenv('MAIL_MAILER'));
89+
$this->assertEquals($smtpPort, getenv('MAIL_PORT'));
90+
$this->assertEquals($smtpEncyption, getenv('MAIL_ENCRYPTION'));
91+
92+
}
4893
}

0 commit comments

Comments
 (0)