Skip to content

Commit

Permalink
Fix from_name issue for database mail
Browse files Browse the repository at this point in the history
  • Loading branch information
iwasherefirst2 committed Jan 13, 2022
1 parent 4887f4a commit 620b32d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/DatabaseConfigMailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function initialize($key): DatabaseConfigMailSettings
}

if (empty($this->name)) {
$this->name = $this->account->from_mail;
$this->name = $this->account->from_name;
}

$this->loadProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function up()
$table->string('host');
$table->string('port');
$table->string('encryption');
$table->string('driver')->default('smtp');
$table->timestamps();
});
}
Expand Down
59 changes: 31 additions & 28 deletions tests/Integration/MultiMailDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,58 @@

namespace IWasHereFirst2\LaravelMultiMail\Tests\Integration;

use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
use Illuminate\Support\Facades\View;
use IWasHereFirst2\LaravelMultiMail\DatabaseConfigMailSettings;
use IWasHereFirst2\LaravelMultiMail\Facades\MultiMail;
use IWasHereFirst2\LaravelMultiMail\Models\EmailAccount;
use IWasHereFirst2\LaravelMultiMail\Models\EmailProvider;
use IWasHereFirst2\LaravelMultiMail\Tests\TestCase;
use IWasHereFirst2\LaravelMultiMail\Tests\Traits\MailTrap;

class MultiMailDatabaseTest extends TestCase
{
const FROM = '[email protected]';
use MailTrap;
const FROM = '[email protected]';

/** @test */
public function check_database_email()
{
$this->artisan(
'migrate',
[
'--database' => 'testbench',
'--realpath' => realpath(__DIR__ . '/../../src/Migrations'),
]
)->run();
$this->loadMigrationsFrom(realpath(__DIR__ . '/../../src/Migrations'));

dd( \DB::table('email_accounts')->get());
$this->artisan('migrate',['--database' => 'testbench'])
->run();

EmailAccount::create([
'email' => 'ronyPuh',
'pass' => 'gomyBore',
$provider = EmailProvider::create([
'host' => env('MAIL_HOST_SMTP'),
'port' => env('MAIL_PORT_SMTP'),
'encryption' => env('MAIL_ENCRYPTION_SMTP'),
'driver' => env('MAIL_DRIVER_SMTP'),
]);

dd(EmailAccount::all());

EmailAccount::create([
'email' => static::FROM,
'pass' => env('MAIL_PASSWORD_SMTP'),
'username' => env('MAIL_USERNAME_SMTP'),
'from_name' => 'Rayn Roogen',
'provider_id' => $provider->id
]);

$to = '[email protected]';
$cc = '[email protected]';
$to = '[email protected]';
$locale = 'de';
$from = static::FROM;
$bcc = ['[email protected]', '[email protected]'];

MultiMail::to($to)
->cc($cc)
->locale($locale)
->from($from)
->bcc($bcc)
->send(new TestMail());

$this->assertNotNull($this->emails);
$this->assertEquals(1, count($this->emails));
$message = $this->findMessage('TestMail Subject');

$this->assertEquals('Rayn Roogen', $message[0]['from_name']);
$this->emptyInbox();
}

/**
Expand All @@ -65,13 +72,11 @@ protected function getEnvironmentSetUp($app)
'prefix' => '',
]);

$app['config']->set('multimail.emails',
['[email protected]' => [
'pass' => 'fakepass',
'username' => 'fakeusername',
'from' => 'Who knows',
'reply_to_mail' => '[email protected]',
]]);
$app->useEnvironmentPath(__DIR__ . '/..');
$app->bootstrapWith([LoadEnvironmentVariables::class]);

$app['config']->set('multimail.mail_settings_class',
DatabaseConfigMailSettings::class);

$app['config']->set('multimail.provider.default', [
'driver' => 'log',
Expand All @@ -81,6 +86,4 @@ protected function getEnvironmentSetUp($app)

View::addLocation(__DIR__ . '/../Fixtures');
}


}

0 comments on commit 620b32d

Please sign in to comment.