Using passes as mail attachments | laravel-mobile-pass | Spatie

 SPATIE

  Laravel Mobile Pass
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-mobile-pass](https://spatie.be/docs/laravel-mobile-pass/v1)  Basic-usage  Using passes as mail attachments

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-mobile-pass/v1)

- [ Introduction ](https://spatie.be/docs/laravel-mobile-pass/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-mobile-pass/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-mobile-pass/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-mobile-pass/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-mobile-pass/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-mobile-pass/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-mobile-pass/v1/about-us)

Basic usage
-----------

- [ Introduction ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/introduction)
- [ Getting credentials from Apple ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/getting-credentials-from-apple)
- [ Generating your first pass ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/generating-your-first-pass)
- [ Associating passes with models ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/associating-passes-with-models)
- [ Updating passes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/updating-passes)
- [ Storing mobile passes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/storing-mobile-passes)
- [ Downloading passes ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/downloading-passes)
- [ Using passes as mail attachments ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/using-passes-as-mail-attachments)
- [ Available pass types ](https://spatie.be/docs/laravel-mobile-pass/v1/basic-usage/available-pass-types)

Advanced usage
--------------

- [ Customizing actions ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/customizing-actions)
- [ Customizing models ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/customizing-models)
- [ Reading stored passes ](https://spatie.be/docs/laravel-mobile-pass/v1/advanced-usage/reading-stored-passes)

 Using passes as mail attachments
================================

In your mail templates, you can attach passes to your emails. This is useful when you want to send a pass to a user after a purchase or when you want to send a pass to a user after they have signed up for a service.

To attach a pass to an email, you can simply return it in the `attachments` method of your Mailable class. Here's an example:

```
class OrderShipped extends Mailable
{
    public MobilePass $pass;

    public function __construct(MobilePass $pass)
    {
        $this->pass = $pass;
    }

    public function attachments()
    {
        return [
            $this->pass,
        ];
    }
}
```

By default, the pass will be attached as a `pass.pkpass` file. If you want to change the filename, you can do so specify the download name when creating the pass:

```
$mobilePass = AirlinePassBuilder::make()
    // this will result as the attachment name being set to 'boarding-pass-john-doe-to-london.pkpass'
    ->setDownloadName('boarding-pass-john-doe-to-london');
    ->setOrganisationName('My organisation')
    -> ... // other pass properties
    ->save();
```
