RickDBCN / filament-email

Log emails in your Filament project
https://filament-email-demo.marcogermani.it/
MIT License
83 stars 22 forks source link

Add model and model_id ? #48

Closed tonypartridge closed 3 months ago

tonypartridge commented 6 months ago

Ideally adding the model sending the email and the model_id would then mean we can have email transactions for the model.

I built something similar whereby we store the id and model so we can then find the transactions and render them in an action on the model record so users can easily see the status of send emails, but I took it one step further and built malign integration and a web hook so we can show status, deliveries and opens/clicks.

jackleblack-kpt commented 6 months ago

Hi, I agree with you. @tonypartridge Do you can share your webhook code about status, deliveries ... or explain me how you do this ? Thank you a lot :)

marcogermani87 commented 6 months ago

Hi, I agree with you. @tonypartridge Do you can share your webhook code about status, deliveries ... or explain me how you do this ? Thank you a lot :)

Hi @tonypartridge, i agree with @jackleblack-kpt you can share more details about your idea?

tonypartridge commented 6 months ago

Sure, so in the EmailSendingListener I get the model and the model_id out of the event data and store it. I am sure from the event we can get the model class though, just not tried yet.

We store the model and model_id and then when viewing records we can see a full history of sending actions.

From here, on the event before returning it, we add in a mailgun variables header with:

$event->message->getHeaders()->addTextHeader('X-Mailgun-Variables', '{"log_id": "'.$log->id.'"}');

Now mailgun will return the log id with every request, (we usually encrypt it before sending it to mailgun to protect the model id).

Next I build a webookhooks route file to handle the incoming hooks you setup in mailgun, and then we get the hook and check for a log_id if one exists, we find it and then store a mail gun log message and update the original sending email with what has happened.

marcogermani87 commented 6 months ago

Sure, so in the EmailSendingListener I get the model and the model_id out of the event data and store it. I am sure from the event we can get the model class though, just not tried yet.

We store the model and model_id and then when viewing records we can see a full history of sending actions.

From here, on the event before returning it, we add in a mailgun variables header with:

$event->message->getHeaders()->addTextHeader('X-Mailgun-Variables', '{"log_id": "'.$log->id.'"}');

Now mailgun will return the log id with every request, (we usually encrypt it before sending it to mailgun to protect the model id).

Next I build a webookhooks route file to handle the incoming hooks you setup in mailgun, and then we get the hook and check for a log_id if one exists, we find it and then store a mail gun log message and update the original sending email with what has happened.

Hi @tonypartridge, the final result can be like this:

image

image

Showing the history of a Log ID append to the first sent e-mail.

The details of every list child can show for example updates on to, cc, bcc, attachments happens through the time.

I'm right?

tonypartridge commented 6 months ago

Yep, but you decide what you handle from the webhooks, at the moment I just store them all and relation what i need.

marcogermani87 commented 5 months ago

Hi @tonypartridge, do you have some code to share with a PR?

RickDBCN commented 3 months ago

Closing this due to inactivity.