craigpaul / laravel-postmark Goto Github PK
View Code? Open in Web Editor NEWA Postmark adapter for Laravel
License: MIT License
A Postmark adapter for Laravel
License: MIT License
Instead of only using Laravel's mail builder schema, this package should have an option to use Postmark's templates API, which is one of the main features of Postmark.
I am trying to add an inline attachment inside my blade email file.
$message->embed(public_path('img/mail/logo.png')) or $message->embed(asset('img/mail/logo.png')) but only what I got in final email is data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
I also tried the official wildbit library recommended by Laravel doc (https://github.com/wildbit/swiftmailer-postmark) and that works fine. I need to continue using this package because I can get MessageID.
The release of Laravel 9.0 is scheduled for January 2022 and it ships with Symfony 6.0. Swift Mailer is replaced by Symfony Mailer.
Relevant pages and PR's to have a look at:
This project provide some features I like which are not present in the Symfony Postmark bridge, most notably sending mails via templates. It is not likely that the Symfony Postmark Bridge will implement this functionality in their project for obvious reasons, looking at a similar case for Mandrill (symfony/symfony#37612).
The changes in Symfony 6.0 and Laravel 9.0 are not backwards compatible and require a serious rewrite of this project (for example run the tests in https://github.com/joostdebruijn/laravel-postmark/tree/3.x). It may be interesting to have a look at the Symfony Postmark Bridge (https://github.com/symfony/postmark-mailer) and extend it where necessary to achieve feature parity with the module at this moment. This reduces maintance on this module while keeping the extra functionality.
Of course I'm very happy to help, but before spending time on this I would like to know what the maintainer of this package thinks of the upcoming changes and the future of this project.
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
If you stick with MAIL_DRIVER=postmark
it does not seem to be a problem.
Using Mail::mailer('postmark')->to(...)
might cause a problem:
laravel-postmark/src/PostmarkServiceProvider.php
Lines 23 to 25 in d2d7200
Think we can remove these stale branches from the repo:
I have a question We are using this package to send emails via postmark but when we try and send a email at a particular time it seems to be failing with Undefined array key "message_stream_id"
[2023-07-26 08:22:48] staging.ERROR: Undefined array key "message_stream_id" {"exception":"[object] (ErrorException(code: 0): Undefined array key "message_stream_id" at /home/forge/staging.solidarity-snp.datakrag.co.za/releases/2023-07-24-17-47-51/vendor/coconutcraig/laravel-postmark/src/PostmarkServiceProvider.php:24)
[stacktrace]
I am getting exceptions in my log for certain emails when people try resetting their password.
(see below) - Is there a recommended way of capturing those or avoiding these altogether?
Using latest version 2.4 with laravel 5.8.8
Message
Client error: `POST https://api.postmarkapp.com/email` resulted in a `422 Unprocessable Entity` response:
{"ErrorCode":406,"Message":"You tried to send to a recipient that has been marked as inactive.\nFound inactive addresses (truncated...)
Level
ERROR
Exception
```{
"class": "GuzzleHttp\\Exception\\ClientException",
"message": "Client error: `POST https:\/\/api.postmarkapp.com\/email` resulted in a `422 Unprocessable Entity` response:\n{\"ErrorCode\":406,\"Message\":\"You tried to send to a recipient that has been marked as inactive.\\nFound inactive addresses (truncated...)\n",
"code": 422,
"file": "\/home\/forge\/www.nanochipid.com\/releases\/20190414015353\/vendor\/guzzlehttp\/guzzle\/src\/Exception\/RequestException.php:113",
"trace": [
...
Postmark can call a webhook on several events.
I am currently maintaining this package to handle these:
https://github.com/mvdnbrk/laravel-postmark-webhooks
Spatie has also a package which does this for their mailcoach app:
https://github.com/spatie/laravel-mailcoach-postmark-feedback
As part of sending an email you probably want to get notified, now these are separate packages.
Maybe we can integrate these together, one package is easier to maintain and these two complement each other.
i try to update to laravel 9
but i can׳t :(
Current namespace is Coconuts
.
Proposing to change this to Craigpaul
.
Postmark has an option for Batch Email sending.
It would be really good if you can add this feature to v3 so we can use Laravel 8 Mailer for our Newsletters.
This is either a question or an enhancement request, or maybe both 😄
I would like to know the message ID of the email that was just sent.
I’m working on a site where I want our admin users to be able to see the delivery status of emails for each user. Using the webhook I can get a message ID, but I don’t have anyway of matching it up with the sent email.
An email is sent to someone using Postmark, and the message ID is recoreded in the database. An admin on our site can see that the email was sent, but has not yet been delivered. When there’s a response, the message is updated, so that if it’s bounced (or other), the admin can manually get in contact with the person.
Any developer that wants to take advantage of the tracking from start-to-finish would find this useful. Useful for important emails (such as legal, buying/selling, recruitment).
Just looking at the code here and in Laravel, it looks like the response is either void
or $this->numberOfRecipients($message)
, so I don’t know how messy it’ll be to get the message ID from the response.
* Yes I know it’s on my list.
Now that we are supporting Laravel 5.5 - 5.7 on v2.3.*, I think it would be best if Travis CI was running tests against each version of Laravel with the appropriate PHP version. Right now it is only going to test against the latest version of laravel/framework on each specified PHP version.
Example Implementations / Ideas:
Travis Configuration for Laravel Package Testing
Testing Multiple Dependency Versions with Travis CI
Laravel Package Development: Testing Against Multiple Laravel Versions
We just tagged the first release candidate for Laravel 9.0 / Symfony 6.0 support, but before a full-fledged release can take place we will need to write up a thorough upgrade guide entry as this is a fairly big breaking change, hopefully, most of the changes are handled as part of the Laravel upgrade though.
See #119
With Laravel 7 as a minimum requirement we can make use of the built in HTTP client which was introduced in L7.
Can also be used with testing.
@craigpaul Seems like https://scrutinizer-ci.com/g/coconutcraig/laravel-postmark/ is outdated and the repo is not analyzed anymore by Scrutinizer.
Replace the Guzzle client with the built in HTTP client provided by the Laravel framework.
Add ability back to override guzzle options like bigger timeouts in config/postmark or at other location.
Sometimes you need bigger timeout or more control about guzzle. That's not possible anymore because of the changes in 3.x
check for guzzle config like other implementations in mailmanager already do or like you did before in 2.x
I'm using this package to send my emails via Postmark (it already works), but I need to store the postmark message ID into DB.
I have an event listener like this, but headers only contains "from","to" and "subject"...
public function handle(MessageSent $event)
{
if (isset($event->data['booking'])) {
$booking = $event->data['booking'];
$messageId = $event->message->getHeaders()->get('x-pm-message-id')?->getValue() ?? $event->message->getHeaders()->get('message-id')->getName();
$booking->mailIdentifiers()->create(['message_identifier' => $messageId]);
}
}
I am trying to figure out how to test the upcoming tls configuration changes on the postmark api : https://postmarkapp.com/updates/upcoming-tls-configuration-changes-for-api-users-action-may-be-required
These changes may affect the application’s ability to continue to send mail through Postmark.
@craigpaul I suggest you should set the default branch to 2.x
while we are working on the main
branch for the upcoming 3.x
release.
Otherwise people may refer to changes we have made which are not released yet.
See https://github.com/github/renaming
Maybe this is a good point to change the master
branch to main
All breaking changes for the upcoming 3.x
release should go to this branch.
I get the following error when sending mail.
DEPRECATED json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in vendor/coconutcraig/laravel-postmark/src/PostmarkTransport.php on line 187.
error.txt
The error is :
No hint path defined for [postmark].
Integration Method using: MailMessage with notifiable in Laravel
I am trying to send an email from existing implementation of laravel notification using postmark email template method.
toMail() which extends by Notification
call from controller using user->notify(with Notification class)
Why is this change important to you? How would you use it?
How can it benefit other users?
Not obligatory, but suggest an idea for implementing addition or change.
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
I have a question,
I am trying to post a "Message-ID" parameter with the headers to the Postmark API so I can thread emails, I also need to post a "In-Reference-To" header parameter as well as "References". This is what I'm currently doing in the build() function of the mailable:
$this->withSwiftMessage(function (\Swift_Message $message) {
$msgId = $message->getHeaders()->get('Message-ID');
$msgId->setId('[email protected]');
$message->getHeaders()->addTextHeader('X-PM-KeepID', 'true');
});
When I dump the headers I can see the new Message-ID, but once it reaches Postmark, it doesn't change.
I encoutered this bug when creating a new TemplatedMailMessage and using the 'alias' directive instead of using an identifier. My code looks like this:
$message = (new TemplatedMailMessage())
->from(
config('mail.from.address'),
config('mail.from.name'))
->alias($this->templateId)
->include($this->templateModel($notifiable));
In the 2.x versions of your package this worked. But in the 3.x version it throws this error:
Error: Typed property CraigPaul\Mail\TemplatedMailMessage::$id must not be accessed before initialization in /.../vendor/coconutcraig/laravel-postmark/src/TemplatedMailMessage.php:27
However, when adding the "identifier" with value '0' it does work:
$message = (new TemplatedMailMessage())
->from(
config('mail.from.address'),
config('mail.from.name'))
->identifier(0)
->alias($this->templateId)
->include($this->templateModel($notifiable));
Change the id property on the TemplatedMailMessage class to this:
protected ?int $id = null;
I'm trying to configure 2 mailers, one for postmark transactionals and another for broadcasts. in the following way, but when I try to send a notification using the "postmark-broadcast" it doesn't take use the message_stream_id of that mailer, instead uses the one from "postmark" mailer. Is this a bug, or am I doing something wrong?
'postmark' => [
'transport' => 'postmark',
],
'postmark-broadcast' => [
'transport' => 'postmark',
'message_stream_id' => env('POSTMARK_BROADCAST_MESSAGE_STREAM', 'broadcast'),
],
public function toMail($notifiable)
{
return (new MailMessage)
->mailer('postmark-broadcast')
->subject($this->company->name.": New Investor Update '".$this->investorUpdate->title."'")
->markdown('emails.new_investor_update', [
'url' => route('investor-update', ['id' => $this->investorUpdate->hash, 'as' => $notifiable->routes['mail']]),
'title' => $this->investorUpdate->title,
'company' => $this->company->name,
'creator' => $this->creator,
'section_title' => $this->firstSection->title,
'section_body' => $this->firstSection->text,
]);
}
When I attempted to use this library to send an email using a template, I noticed the email body was always empty. After tracing around the code, I found that the output from the postmark::template
view (https://github.com/craigpaul/laravel-postmark/blob/5481b9ad178fddc919fa717c9ae25eb7cc6b72ce/resources/views/template.blade.php) was always empty and I never received any feedback in output (logs, console etc). Further digging and I discovered that the data was getting into the render function, however, the output was always empty.
After some more poking around I ended up in Illuminate\View\View::gatherData()
. There is a line that adds "shared" data of __env
and app
. Removing these allows the template to render. It seems there is just too much data in these array fields.
To solve the problem, I paired down the data by changing the template from:
@json($__data)
to:
{
"id": @json($id),
"alias": @json($alias),
"model": @json($model)
}
I am unclear why there is so much data, but, at least this solves the problem. For reference, I am extending PostmarkTemplateMailable
and overloading the __construct()
and build()
methods which is being called via
Mail::to("[email protected]")
->send(new OrderReceived($order))
;
Here is my Mailable class for reference
<?php
namespace App\Mail;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Coconuts\Mail\PostmarkTemplateMailable;
class OrderReceived extends PostmarkTemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* The order instance.
*
* @var \App\Models\Order
*/
protected $order;
/**
* Create a new message instance.
*
* @param \App\Models\Order $order
* @return void
*/
public function __construct(Order $order)
{
parent::__construct();
$this->order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->afterCommit()
->id(12345)
->include([
"product_url" => "product_url_Value",
"product_name" => "product_name_Value",
"name" => "name_Value",
"action_url" => "action_url_Value",
"support_email" => "support_email_Value",
"company_name" => "company_name_Value",
"company_address" => "company_address_Value",
])
;
}
}
$config['message_stream_id']
is not defined, and so it triggers a PHP error - maybe it should be $config['message_stream_id'] ?? ''
, or something similar. Am I meant to be defining message_stream_id
somewhere? It feels like a default (i.e. not defining it) should be ok.
It would be nice to be able to send mails with a template based on the Mailable class. Now it is only possible to send mails based on templates via Notifications.
I don't want to use the more advanced Notifications-stuff, but I would like to use the Mail functionality with Postmark templates.
It would be nice if a template and data could be provided in build()
of a Mailable.
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
Postmark uses the concept of servers.
Each server has its own api token.
At the moment there is only one way to set this api token, with POSTMARK_SECRET
env variable.
If an app requires sending messages to different servers this can not be done easily.
We should add the ability to set the api token on the fly.
At this point if someone forgets to set the POSTMARK_SECRET
an exception of GuzzleHttp\Exception\ClientException
will be thrown.
Client error: 'POST https://api.postmarkapp.com/email' resulted in a '422 Unprocessable Entity'
We should prevent this from happening by checking if the POSTMARK_SECRET
was set.
Let's keep an eye on this PR:
laravel/framework#29325
public function getApiEndpoint(Swift_Mime_SimpleMessage $message)
{
if ($this->templated($message)) {
$this->apiEndpoint .= '/withTemplate';
}
return $this->apiEndpoint;
}
This keeps appending '/withTemplate' to the api endpoint statefully, resulting in requests like
POST https://api.postmarkapp.com/email/withTemplate/withTemplate/withTemplate/withTemplate/withTemplate/withTemplate/withTemplate resulted in a 404 Not Found response.
Hello. In the last commit (called "Adds support for passing in Guzzle options to the Laravel HTTP client") following line has been added in src/PostmarkServiceProvider.php
$config = $this->app->make('config');
unfortunately this overwrites the value of existing $config parameter, therefore few lines further down, the "$config['message_stream_id']" is always null.
If you add dd($config) prior to line 22, you'll see the value of message_stream_id (if defined in mail.php). After line 23 it's undefined because the $config is overwritten.
Could you please check? It's easily replicable.
Thanks!
I think we can remove travis
and move to Github actions.
Do we still need scrutinzer
? Does this really add value?
We could move this to a static analyzer like phpstan
or psalm
(and run with a GH action).
What do you think @craigpaul ?
Postmark has introduced Message Streams.
I think we should add a way to specify a Stream ID:
MessageStream
parameter to the json, which defaults to outbound
.See: https://postmarkapp.com/support/article/1207-how-to-create-and-send-through-message-streams
I'm trying to use the MailMessage class to send in postmark template, the configuration is correct but I receive a json as a message to my mailbox.
this is my implementation
this is my response
{"__env":{},"app":{"contextual":[]},"id":18999584,"alias":"user-c=
onfirmation","model":{"name":"Usuario","product_name":"Maquillate=
.com","action_url":"https://dev.maquillate.com/confirmation","=
login_url":"https://dev.maquillate.com/login","username":"Usua=
rio"},"__laravel_notification_id":"02bb8627-5d08-485f-9122-4e7091=
79f8c1","__laravel_notification":"App\Notifications\UserConfirm=
ation","__laravel_notification_queued":false,"message":{}}=0D=0A
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
Postmark has different response codes when you are sending messages.
For example a 422
response code is returned when you try to send to a recipient that has been marked as inactive.
With the current implementation all exceptions on Postmark's end leads to a GuzzleHttp\Exception\ClientException
.
I am proposing a custom exception which you can catch.
In my use case I can ignore a 422
exception, while a 429 / Rate Limit Exceeded can be catched and I am able to try to send to message again later.
See https://postmarkapp.com/developer/api/overview#response-codes
After updating my Laravel app to v7, postmark stopped working. I kept on receiving error code "550 5.7.1". It took me a long time to find where the catch was, as I moved my app to a fresh server at the same time.
It turned out to be a small detail in the .ENV file, as Laravel 7.0 uses MAIL_MAILER instead of MAIL_DRIVER to select the mailing protocol.
Please update your documentation (see screenshot below) so that it mentions also the MAIL_MAILER for Laravel v7 (and higher) option for configuring your postmark driver.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.