A simple mailable trait and interface to export mails to a storage disk once being sent.

Overview

Laravel Mail Export

Latest Version on Packagist GitHub Workflow Status Software License Total Downloads

This package can export any mail sent with Laravel's Mailable class to any desired filesystem disk and path as a .eml file.

This can be useful when wanting to store emails sent for archive purposes.

Installation

You can install the package via composer:

For Laravel 5.x and 6.x

composer require pod-point/laravel-mail-export:^0.1

For Laravel 7.x and 8.x

composer require pod-point/laravel-mail-export:^0.2

Publishing the config file

The configuration for this package comes with some sensible values but you can optionally publish the config file with:

php artisan vendor:publish --provider="PodPoint\MailExport\MailExportServiceProvider"

You will be able to specify:

  • enabled: wether this package is enabled or not.
  • disk: which disk to use by default. null will use the default disk from your application filesystem.
  • path: the default path you would like to export your mails within a storage disk.

See our config/mail-export.php for more details.

Usage

Simply add the Exportable trait and the ShouldExport interface to any Mailable class that you want to persist into any storage disk.



namespace App\Mail;

use Illuminate\Mail\Mailable;
use PodPoint\MailExport\Concerns\Exportable;
use PodPoint\MailExport\Contracts\ShouldExport;

class OrderShipped extends Mailable implements ShouldExport
{
    use Exportable;
    
    // ...
}

This will use the default filesystem disk and path from the configuration and will also generate a unique filename for you.

The default filename is using a timestamp, the mail recipients, the subject and will look like so:

2021_03_26_150142_jane_at_example_com_this_is_the_subject.eml

You can also specify the disk, path or filename to use for a specific Mailable using properties:



namespace App\Mail;

use Illuminate\Mail\Mailable;
use PodPoint\MailExport\Concerns\Exportable;
use PodPoint\MailExport\Contracts\ShouldExport;

class OrderShipped extends Mailable implements ShouldExport
{
    use Exportable;
    
    public $exportDisk = 'some_disk';

    public $exportPath = 'some_path';

    public $exportFilename = 'some_filename';
    
    // ...
}

You can also use methods if you need more flexibility:



namespace App\Mail;

use Illuminate\Mail\Mailable;
use PodPoint\MailExport\Concerns\Exportable;
use PodPoint\MailExport\Contracts\ShouldExport;

class OrderShipped extends Mailable implements ShouldExport
{
    use Exportable;
    
    // ...
    
    public function exportDisk(): string
    {
        return 'some_disk';
    }

    public function exportPath(): string
    {
        return 'some_path';
    }

    public function exportFilename(): string
    {
        return 'some_filename';
    }
}

Then you can keep using your Mailable as usual:

Mail::to($request->user())->send(new OrderShipped($order));

Even with Notifications too:



namespace App\Notifications;

use App\Mail\OrderShipped as Mailable;
use Illuminate\Notifications\Notification;

class OrderShipped extends Notification
{
    // ...
    
    public function toMail($notifiable)
    {
        return (new Mailable($this->order))->to($notifiable->email);
    }    
}

Testing

Run the tests with:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


Travel shouldn't damage the earth 🌍

Made with ❤️   at Pod Point

You might also like...
Greyhole uses Samba to create a storage pool of all your available hard drives, and allows you to create redundant copies of the files you store.

Greyhole Greyhole is an application that uses Samba to create a storage pool of all your available hard drives (whatever their size, however they're c

Laravel & Google Drive Storage - Demo project with Laravel 6.x and earlier

Laravel & Google Drive Storage Demo project with Laravel 8.X Look at the commit history to see each of the steps I have taken to set this up. Set up t

File uploads with validation and storage strategies

Upload This component simplifies file validation and uploading. Usage Assume a file is uploaded with this HTML form: form method="POST" enctype="mult

PHP Project - Export your profile to vCard file

KamVCard PHP v1.00 Easy to have your own vCard file, fill in the form and hit the "Export" button UPDATE : Now you can add your picture too ! Preview

Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel
Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel

Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel , mapping of any format, Google Sheet, data and price modification, improved speed and a lot more!

Import/Export configuration data in Magento 2 via CLI.

ConfigImportExport This module provides new CLI commands for Magento 2 to import/export data in/from core_config_data. This module is inspired by the

N2Web turns your Notion HTML export into a fully functional static website
N2Web turns your Notion HTML export into a fully functional static website

Notion2Web N2Web turns your Notion HTML export into a fully functional static website. What is Notion? Notion is an online tool. But I can't tell you

Import/Export configuration data in Magento 2 via CLI.

ConfigImportExport This module provides new CLI commands for Magento 2 to import/export data in/from core_config_data. This module is inspired by the

 Magento 2 - Improved Import / Export extension
Magento 2 - Improved Import / Export extension

Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel , mapping of any format, Google Sheet, data and price modification, improved speed and a lot more!

Comments
  • Seems not to work with cloud storage (s3 / digitalocean spaces)

    Seems not to work with cloud storage (s3 / digitalocean spaces)

    Hi, firstly thanks for the awesome package. Thumbs up for the good work.

    Do you have an idea why I can not get the emails saved to the remote storage? I'm using DigitalOcean Spaces which runs on AWS S3. I'm getting no errors but also no .eml files. For now I can work around this issue, but it would be nice if it would work on it's own.

    opened by Artem-Schander 2
  • default filesystem disk is asked from the wrong config file

    default filesystem disk is asked from the wrong config file

    in pod-point\laravel-mail-export\src\StorageOptions.php the default filesystem disk is asked from config('filesystem.default') , but in Laravel 7/8 it should be config('filesystems.default') as the filename is filesystems instead of filesystem

    @see (pod-point\laravel-mail-export\src\StorageOptions.php)

         * Build the default storage disk using the config if none is provided by the developer.
         *
         * @return string
         */
        private function defaultDisk(): string
        {
            return config('mail-export.disk') ?: config('filesystem.default');
        }
    

    @Laravel-Repo https://github.com/laravel/laravel/blob/7.x/config/filesystems.php

    bug 
    opened by Thommis 2
  • Initial release

    Initial release

    Supports PHP:

    • 7.1
    • 7.2
    • 7.3
    • 7.4

    Supports Laravel:

    • 5.x
    • 6.x

    Will need to release this as v1.0.0 and then do a v2.0.0 for supporting PHP8 + Laravel 7.x & 8.x

    opened by clemblanco 0
Releases(2.0.0)
  • 2.0.0(Aug 5, 2022)

    What's Changed

    • [2.x] Laravel 9 Support Only - Breaking change by @clemblanco in https://github.com/Pod-Point/laravel-mail-export/pull/17
    • Moved from swiftmailer/swiftmailer to symfony/mailer
    • Thank you to @fridzema for contributing in https://github.com/Pod-Point/laravel-mail-export/pull/14

    Full Changelog: https://github.com/Pod-Point/laravel-mail-export/compare/1.0.0...2.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Pod Point
Travel shouldn't damage the earth.
Pod Point
Get the system resources in PHP, as memory, number of CPU'S, Temperature of CPU or GPU, Operating System, Hard Disk usage, .... Works in Windows & Linux

system-resources. A class to get the hardware resources We can get CPU load, CPU/GPU temperature, free/used memory & Hard disk. Written in PHP It is a

Rafael Martin Soto 10 Oct 15, 2022
A trait to make building your own custom Laravel Model Searches a lot easier.

BrekiTomasson\LaravelModelFinder A simple trait that makes building your own custom Laravel Model Searches a lot easier and safer. It ensures that you

Breki Tomasson 3 Nov 27, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
Import data from and export data to a range of different file formats and media

Ddeboer Data Import library This library has been renamed to PortPHP and will be deprecated. Please use PortPHP instead. Introduction This PHP library

David de Boer 570 Dec 27, 2022
This is an experiment to export all RFCs from the PHP wiki into Git, including the change history for each RFC (along with the date and author of each change). This is not meant to replace the wiki.

PHP Requests for Comments (RFCs) About This repository is an experiment to export all RFCs from the PHP wiki into Git, including the change history fo

Ben Ramsey 34 Jun 20, 2022
Tool for easy selection and export of user files in ZIP format.

Personal data export Idea Tool for easy selection and export of user files in ZIP format. Within a single selector, you choose all user data (much of

Baraja packages 2 Oct 18, 2021
Q2A plugin that allows users to import and export Q2A configuration

Configuration Manager [by Gabriel Zanetti] Description Configuration Manager is a Question2Answer plugin that allows users to import and export Q2A co

Gabriel Zanetti 1 Nov 22, 2021
Silverstripe-sspy - Python based SSPAK export with higher reliability and cross-platform compatibility

SSPY - Python Stand-alone SSPAK solution © Simon Firesphere Erkelens; Moss Mossman Cantwell Usage: sspy [create|load|extract] (db|assets) --file=my.

Simon Erkelens 1 Jun 29, 2021
Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

Bippo Indonesia 23 Dec 20, 2022
Silverstripe module allowing editors to create newsletters using elemental blocks and export them to a sendy instance

Silverstripe Sendy Silverstripe module allowing editors to create newsletters using elemental blocks and export them to a sendy instance. Introduction

Syntro Opensource 4 Apr 20, 2022