bengor-user/swift-mailer-bridge
SwiftMailerBridge provides an adapter to make BenGorUser User objects compatible with SwiftMailer, enabling seamless use of your user domain model when addressing and sending emails via SwiftMailer in PHP applications.
BenGorUser) and email infrastructure (SwiftMailer), aligning with Laravel’s dependency inversion and SOLID principles. This is particularly valuable in monolithic applications where user-related emails are scattered across controllers/services.Mailable classes handle email templating, this bridge specializes in user-specific email logic (e.g., dynamic placeholders like {user.name} or {user.reset_token}). It can coexist with Laravel’s mail system by acting as a pre-processor for user data before rendering templates.BenGorUser-style model. If the Laravel app uses a custom user model (e.g., App\Models\User), the bridge would require an adapter layer to map properties (e.g., email → getEmailAddress()).Mailable to use the bridge for user data injection.
public function build()
{
$user = auth()->user();
$message = (new \SwiftMailerBridge\UserMessage())
->setUser($user)
->setSubject('Reset Password');
return $this->withSwiftMessage($message)
->markdown('emails.reset');
}
PasswordReset event) to generate emails before dispatching via Laravel’s Mail::send.{user.name}), which can be mapped to Laravel’s Blade/Markdown variables or SwiftMailer’s setBody().UserMessage can be serialized and passed to Laravel’s queue system for async email delivery.Notification system + custom MailChannel.Mailable + Notification suffices, the bridge may not justify its risks.BenGorUser a hard dependency?
Mailable classes by handling user-specific email logic (e.g., token generation, dynamic data).swiftmailer/swiftmailer) is fully compatible. The bridge leverages SwiftMailer’s Message class for advanced features (e.g., embedded images, HTML emails).Notification system with MailChannel may replace the bridge entirely.Mailable are sufficient.{user.name} placeholders, Laravel’s Mailable + Blade can achieve this without the bridge.Mailable/Notification.your-team/swiftmailer-bridge-laravel).App\Models\User), create an adapter interface:
interface UserAdapter {
public function getEmail();
public function getName();
public function getResetToken(); // Example
}
Notification system or custom logic.Notification system, reducing maintenance overhead.try/catch blocks.Mailable).Mail facade already handles retries/queues.How can I help you explore Laravel packages today?