darvinstudio/webmail-linker
Laravel package that generates webmail compose links for common providers (Gmail, Outlook, Yahoo, etc.). Create “email us” URLs with prefilled to/cc/bcc/subject/body so users can open their preferred webmail quickly.
Installation:
composer require darvinstudio/webmail-linker
Add to composer.json if not auto-loaded:
"autoload": {
"psr-4": {
"App\\": "app/",
"Darvinstudio\\WebmailLinker\\": "vendor/darvinstudio/webmail-linker/src/"
}
}
Run composer dump-autoload.
First Use Case: Redirect users to their email provider's webmail interface:
use Darvinstudio\WebmailLinker\WebmailLinker;
$linker = new WebmailLinker();
$email = 'user@example.com';
$url = $linker->getWebmailUrl($email);
return redirect()->to($url);
Key Files:
src/WebmailLinker.php (core logic)src/Providers/ (provider-specific rules)Email-to-Webmail Redirect:
// In a controller/middleware
public function redirectToWebmail(Request $request) {
$linker = app(WebmailLinker::class);
$url = $linker->getWebmailUrl($request->user()->email);
return redirect()->away($url);
}
Dynamic Provider Detection:
$provider = $linker->detectProvider('user@outlook.com'); // Returns 'outlook'
$url = $linker->getWebmailUrl('user@outlook.com', $provider);
Custom Provider Integration:
// Extend the linker (see Gotchas)
$linker->addProvider('custom', 'https://custom.com/webmail?email={email}');
public function handle($request, Closure $next) {
if ($request->user() && $request->has('redirect_to_webmail')) {
return redirect()->away(app(WebmailLinker::class)->getWebmailUrl($request->user()->email));
}
return $next($request);
}
@foreach($linker->getProviders() as $provider => $config)
<a href="{{ $linker->getWebmailUrl($email, $provider) }}">
{{ ucfirst($provider) }} Webmail
</a>
@endforeach
return response()->json([
'webmail_url' => $linker->getWebmailUrl($email),
'provider' => $linker->detectProvider($email)
]);
Outdated Provider List:
$linker->setProviderUrl('gmail', 'https://mail.google.com/mail/?view=cm&fs=1&to={email}');
Domain-Specific Rules:
@gmail.com). Custom domains (e.g., @company.com) may not work.$linker->addDomainRule('company.com', 'custom_provider');
No HTTPS Enforcement:
http://. Validate/sanitize URLs:
$url = str_replace('http://', 'https://', $linker->getWebmailUrl($email));
Rate Limiting:
$url = Cache::remember("webmail_url_{$email}", now()->addHours(1), function() use ($email) {
return $linker->getWebmailUrl($email);
});
$provider = $linker->detectProvider($email);
\Log::debug("Detected provider for {$email}: {$provider}");
dd($linker->getProviders()); // See all registered providers
$linker->addProvider('protonmail', 'https://mail.proton.me/webmail');
$linker->setDomainProvider('company.com', 'custom');
WebmailLinker class and override getWebmailUrl():
class CustomWebmailLinker extends WebmailLinker {
public function getWebmailUrl($email, $provider = null) {
$url = parent::getWebmailUrl($email, $provider);
return str_replace('{email}', urlencode($email), $url);
}
}
$linker = new WebmailLinker([
'default_provider' => 'gmail',
'fallback_url' => 'https://example.com/webmail'
]);
How can I help you explore Laravel packages today?