spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

Add attachments to campaign #231

Closed fxkopp closed 3 years ago

fxkopp commented 3 years ago

Is it possible to add attachments to a campaign via Mailcoach API?

I think Mailcoach is using the underlying Laravel Mail function - so maybe there is a way to access this function?

Thanks!

freekmurze commented 3 years ago

Currently there's no full API for mailcoach, but we do plan on adding one in future.

fxkopp commented 3 years ago

So at the moment there is no way to manipulate (add attachment) the campaign before sending?

freekmurze commented 3 years ago

You could use a custom mailable for the campaign where you attach something to the mail

https://mailcoach.app/docs/v2/package/advanced-usage/using-custom-mailables https://laravel.com/docs/master/mail#attachments

dom235 commented 3 years ago

Cheers for your great Package! I had to comment on this issue as we encountered the same problem using latest laravel 7+, latest mailcoach 2+

There is one big issue with your SendMailAction which makes it impossible for us to use very custom mailables

Line 47,48 /* @var \Spatie\Mailcoach\Mails\CampaignMail $campaignMail / $campaignMail = app(CampaignMail::class);

Sure, we can use laravel's IOC container but what do we do, if we have very dynamic mailables?

To give you an idea. I'm not a superior developer but in fact, we need to do something like this

$campaignMail = MailableFactory::make($pendingSend->campaign);

And within that make method, something like

abstract class MailableFactory
{
    public static function make(Campaign $campaign): Mailable
    {
        $mailable = static::getMailable($campaign->slug);

        return (new $mailable())->setCampaign($campaign);
    }

    public static function getMailable(string $slug): ?string
    {
        // our secret project voodoo
    }
}

Which then results in veery different mailables - to meed our business rules. To give you an idea:

and so on..

But hey, we are SO thankful, that we are able to override the SendMailAction actionable class. But in turn, we have to copy your code 1:1 into our codebase to change one line of code. Our maintenance will suffer from this.

Have a great day!