Webador / SlmMail

Send mail from Laminas or Mezzio using external mail services.
Other
106 stars 49 forks source link

Return Postmark API response #79

Closed markushausammann closed 10 years ago

markushausammann commented 10 years ago

I just sent a few first messages with the Postmark service and it works. I'm a bit disapointed that the transport::send() method doesn't return the API response.

The Postmark API responds like this:

{
  "ErrorCode" : 0,
  "Message" : "OK",
  "MessageID" : "b7bc2f4a-e38e-4336-af7d-e6c392c2f817",
  "SubmittedAt" : "2010-11-26T12:01:05.1794748-05:00",
  "To" : "receiver@example.com"
}

The MessageID is very helpful for direct bounce tracking. Is there a reason why you don't preserve the API response?

markushausammann commented 10 years ago

I just realized that the only thing you need to do is changing:

/**
 * {@inheritDoc}
 */
public function send(Message $message)
{
    $this->service->send($message);
}

to

/**
 * {@inheritDoc}
 */
public function send(Message $message)
{
    return $this->service->send($message);
}

in SlmMail\Mail\Transport\HttpTransport.php. Because the service::send() method returns the response correctly.

bakura10 commented 10 years ago

Hi,

Actually the transport implement the TransportInterface and, if I remember correctly, the interface states that it should return "void".

Instead, you should inject the PostmarkService

markushausammann commented 10 years ago

Yeah, I guess that's better/more correct. I'm closing this but I've got another one already. :)

juriansluiman commented 10 years ago

@bakura10 you are right the transport does not return anything but for example the File transport holds state of the last sent message. We could do something similar.

public function send(Message $message)
{
    $this->response = $this->service->send($message);
}

public function getLastRawResponse()
{
    return $this->response;
}

That is similarly named to the Http client for the last sent request & response. That way all SlmMail transports can be used to fetch the transport's send() response too while adhering to the zf2 transport interface.

markushausammann commented 10 years ago

I'm still not happy with this. If you want to be able to swap transports (injecting with Interfaces only) you should be able to get to the API response via Transport. Do you get my point, do you have an idea how to solve this?

markushausammann commented 10 years ago

Actually, re-reading @juriansluiman 's last post I see that that would indeed be the way to go. I'll provide a pull request for that.

markushausammann commented 10 years ago

See respective pull request here: https://github.com/juriansluiman/SlmMail/pull/82

juriansluiman commented 10 years ago

Closing, as discussion continued (and closed) in #82