Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I integrate custom email services for verification in Jetstream


Can I integrate custom email services for verification in Jetstream


Yes, you can integrate custom email services for email verification in Laravel Jetstream. Jetstream uses the default Laravel email functionality, which allows you to customize the email service used for sending verification emails.

Here's how you can integrate a custom email service with Jetstream:

1. Configure the Email Driver:
- In your application's `.env` file, update the `MAIL_DRIVER` and other related email configuration variables to use your desired email service, such as SendGrid, Mailgun, or Amazon SES.
- For example, if you want to use SendGrid, you would update the following variables:


     MAIL_DRIVER=sendgrid
     SENDGRID_API_KEY=your_sendgrid_api_key
     

2. Customize the Verification Email Template:
- Jetstream uses a Blade view for the verification email template, located at `resources/views/auth/verify-email.blade.php`.
- You can customize the content and styling of this view to match your application's branding and requirements.

3. Customize the Verification Notification:
- Jetstream uses the `Illuminate\Auth\Notifications\VerifyEmail` notification class to send the verification email.
- You can create a custom notification class that extends this class and customize the notification's content and delivery.
- For example, you can override the `toMail()` method to use your custom email service:

php
     namespace App\Notifications;

     use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailNotification;
     use Illuminate\Notifications\Messages\MailMessage;

     class VerifyEmail extends VerifyEmailNotification
     {
         public function toMail($notifiable)
         {
             return (new MailMessage)
                 ->subject('Verify Your Email Address')
                 ->line('Please click the button below to verify your email address.')
                 ->action('Verify Email', url('/email/verify', $this->verificationUrl($notifiable)))
                 ->from('
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy54857 = 'y&#111;&#117;r_c&#117;st&#111;m_&#101;m&#97;&#105;l' + '&#64;';
 addy54857 = addy54857 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy54857 + suffix + '\'' + attribs + '>' );
 document.write( addy54857 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>', 'Your App Name');
         }
     }
     

4. Update the Notification in Jetstream:
- In your `App\Providers\JetstreamServiceProvider`, update the `verifyEmailUsing()` method to use your custom `VerifyEmail` notification class:

php
     public function boot()
     {
         $this->configurePermissions();

         Jetstream::verifyEmailUsing(function ($user) {
             return (new App\Notifications\VerifyEmail($user))->toMail($user);
         });
     }
     

By following these steps, you can integrate a custom email service, such as SendGrid, Mailgun, or Amazon SES, for sending the email verification emails in your Jetstream-based application. This allows you to leverage the features and functionality provided by Jetstream while using your preferred email service provider.

Remember to update the email configuration variables in your `.env` file and customize the email template and notification class to match your application's requirements.

Citations:
[1] https://www.youtube.com/watch?v=-nzeLnmcseY
[2] https://jetstream.laravel.com
[3] https://www.twilio.com/en-us/blog/laravel-breeze-vs-laravel-jetstream
[4] https://github.com/laravel/jetstream/actions/runs/9151501616/workflow
[5] https://www.noaa.gov/jetstream/global/jet-stream