ido50 / WWW-Postmark

API for the Postmark mail service (postmarkapp.com) for web applications.
http://search.cpan.org/dist/WWW-Postmark
6 stars 4 forks source link

NAME

WWW::Postmark - API for the Postmark mail service for web applications.

SYNOPSIS

    use WWW::Postmark;

    my $api = WWW::Postmark->new('api_token');

    # or, if you want to use SSL
    my $api = WWW::Postmark->new('api_token', 1);

    # send an email
    $api->send(from => 'me@domain.tld', to => 'you@domain.tld, them@domain.tld',
    subject => 'an email message', body => "hi guys, what's up?");

DESCRIPTION

The WWW::Postmark module provides a simple API for the Postmark web service, that provides email sending facilities for web applications. Postmark is located at http://postmarkapp.com. It is a paid service that charges according the amount of emails you send, and requires signing up in order to receive an API token.

You can send emails either through HTTP or HTTPS with SSL encryption. You can send your emails to multiple recipients at once (but there's a 20 recipients limit). If WWW::Postmark receives a successful response from the Postmark service, it will return a true value; otherwise it will die.

To make it clear, Postmark is not an email marketing service for sending email campaigns or newsletters to multiple subscribers at once. It's meant for sending emails from web applications in response to certain events, like someone signing up to your website.

Postmark provides a test API token that doesn't really send the emails. The token is 'POSTMARK_API_TEST', and you can use it for testing purposes (the tests in this distribution use this token).

Besides sending emails, this module also provides support for Postmark's spam score API, which allows you to get a SpamAssassin report for an email message. See documentation for the spam_score() method for more info.

METHODS

new( [ $api_token, $use_ssl] )

Creates a new instance of this class, with a Postmark API token that you've received from the Postmark app. By default, requests are made through HTTP; if you want to send them with SSL encryption, pass a true value for $use_ssl.

If you do not provide an API token, you will only be able to use Postmark's spam score API (you will not be able to send emails).

Note that in order to use SSL, HTTP::Tiny requires certain dependencies to be installed. See "SSL SUPPORT" in HTTP::Tiny for more information.

send( %params )

Receives a hash representing the email message that should be sent and attempts to send it through the Postmark service. If the message was successfully sent, a hash reference of Postmark's response is returned (refer to the relevant Postmark documentation); otherwise, this method will croak with an approriate error message (see "DIAGNOSTICS" for a full list).

The following keys are required when using this method:

You can optionally supply the following parameters as well:

spam_score( $raw_email, [ $options ] )

Use Postmark's SpamAssassin API to determine the spam score of an email message. You need to provide the raw email text to this method, with all headers intact. If $options is 'long' (the default), this method will return a hash-ref with a 'report' key, containing the full SpamAssasin report, and a 'score' key, containing the spam score. If $options is 'short', only the spam score will be returned (directly, not in a hash-ref).

If the API returns an error, this method will croak.

Note that the SpamAssassin API is currently HTTP only, there is no HTTPS interface, so the use_ssl option to the new() method is ignored here.

For more information about this API, go to http://spamcheck.postmarkapp.com.

DIAGNOSTICS

The following exceptions are thrown by this module:

CONFIGURATION AND ENVIRONMENT

WWW::Postmark requires no configuration files or environment variables.

DEPENDENCIES

WWW::Postmark depends on the following CPAN modules:

WWW::Postmark recommends Cpanel::JSON::XS for parsing JSON (the Postmark API is JSON based). If installed, JSON::MaybeXS will automatically load Cpanel::JSON::XS or JSON::XS. For SSL support, IO::Socket::SSL and Net::SSLeay will also be needed.

INCOMPATIBILITIES WITH OTHER MODULES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-WWW-Postmark@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Postmark.

AUTHOR

Ido Perlmuter ido@ido50.net

With help from: Casimir Loeber.

LICENSE AND COPYRIGHT

Copyright 2017 Ido Perlmuter

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.