NAME
Email::Sender::Transport::Mailgun - Mailgun transport for Email::Sender
SYNOPSIS
use Email::Sender::Simple qw( sendmail );
use Email::Sender::Transport::Mailgun qw( );
my $transport = Email::Sender::Transport::Mailgun->new(
api_key => '...',
domain => '...',
);
my $message = ...;
sendmail($message, { transport => $transport });
DESCRIPTION
This transport delivers mail via Mailgun's messages.mime API.
Why use this module?
The SMTP transport can also be used to send messages through Mailgun. In this case, Mailgun options must be specified with Mailgun-specific MIME headers.
This module exposes those options as attributes, which can be set in code, or via EMAIL_SENDER_TRANSPORT_
environment variables.
Why not use this module?
This module uses Mailgun's messages.mime API, not the full-blown messages API.
If you want to use advanced Mailgun features such as templated batch mailouts or mailing lists, you're better off using something like WebService::Mailgun or WWW::Mailgun.
REQUIRED ATTRIBUTES
The attributes all correspond directly to Mailgun parameters.
api_key
Mailgun API key. See https://documentation.mailgun.com/en/latest/api-intro.html#authentication-1
domain
Mailgun domain. See https://documentation.mailgun.com/en/latest/api-intro.html#base-url-1
OPTIONAL ATTRIBUTES
These (except region) correspond to the o:
options in the messages.mime
section of https://documentation.mailgun.com/en/latest/api-sending.html#sending
deliverytime
Desired time of delivery. String or DateTime object.
dkim
Enables/disables DKIM signatures. 'yes'
or 'no'
.
region
Defines used Mailgun region. 'us'
(default) or 'eu'
.
See https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions-1
retry_count
retry_delay_seconds
If the Mailgun API request fails with a 5xx response, the request will be retried retry_count
times, with a delay of retry_delay_seconds
between each attempt.
Defaults to three retries with a one second delay.
tag
Tag string. Comma-separated string list or arrayref of strings.
testmode
Enables sending in test mode. 'yes'
or 'no'
.
tracking
Toggles tracking. 'yes'
or 'no'
.
tracking_clicks
Toggles clicks tracking. 'yes'
, 'no'
or 'html_only'
.
tracking_opens
Toggles open tracking. 'yes'
or 'no'
.
MIME HEADERS
The o:
options above can also be specified using the X-Mailgun-
headers listed here https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
If a single-valued option is specified in both the options and the headers, experimentation shows the header takes precedence. This doesn't seem to be documented, so don't rely on this behaviour.
Multi-valued options use both the options and the headers.
ENVIRONMENT
The great strength of Email::Sender is that you don't need to hardcode your transport, nor any of the options relating to that transport. They can all be specified via environment variables.
To select the Mailgun transport, use EMAIL_SENDER_TRANSPORT=Mailgun
.
To specify any of the attributes above, prepend the attribute name with EMAIL_SENDER_TRANSPORT_
.
- EMAIL_SENDER_TRANSPORT_api_key
- EMAIL_SENDER_TRANSPORT_domain
- EMAIL_SENDER_TRANSPORT_deliverytime
- EMAIL_SENDER_TRANSPORT_dkim
- EMAIL_SENDER_TRANSPORT_region
- EMAIL_SENDER_TRANSPORT_retry_count
- EMAIL_SENDER_TRANSPORT_retry_delay_seconds
- EMAIL_SENDER_TRANSPORT_tag
- EMAIL_SENDER_TRANSPORT_testmode
- EMAIL_SENDER_TRANSPORT_tracking
- EMAIL_SENDER_TRANSPORT_tracking_clicks
- EMAIL_SENDER_TRANSPORT_tracking_opens
LICENSE
Copyright (C) Stephen Thirlwall.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Stephen Thirlwall <sdt@cpan.org>