azuma, kuniyuki > Haineko-0.2.16 > Haineko::SMTPD::Relay::SendGrid

Download:
Haineko-0.2.16.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Haineko::SMTPD::Relay::SendGrid - SendGrid Web API class for sending email

DESCRIPTION ^

Send an email to a recipient via SendGrid using Web API.

SYNOPSIS ^

    use Haineko::SMTPD::Relay::SendGrid;
    my $h = { 'Subject' => 'Test', 'To' => 'neko@example.org' };
    my $v = { 
        'username' => 'api_user', 
        'password' => 'api_key',
        'ehlo' => 'UserAgent name for Furl',
        'mail' => 'kijitora@example.jp',
        'rcpt' => 'neko@example.org',
        'head' => $h,
        'body' => 'Email message',
    };
    my $e = Haineko::SMTPD::Relay::SendGrid->new( %$v );
    my $s = $e->sendmail;

    print $s;                   # 0 = Failed to send, 1 = Successfully sent
    print $e->response->error;  # 0 = No error, 1 = Error
    print $e->response->dsn;    # always returns undef
    print $e->response->code;   # HTTP response code from SendGrid API

    warn Data::Dumper::Dumper $e->response;
    $VAR1 = bless( {
             'dsn' => undef,
             'error' => 0,
             'code' => '200',
             'host' => 'sendgrid.com',
             'port' => 443,
             'rcpt' => 'neko@example.org',
             'message' => [ 'OK' ],
             'command' => 'POST'
            }, 'Haineko::SMTPD::Response' );

CLASS METHODS ^

new( %arguments )

new() is a constructor of Haineko::SMTPD::Relay::SendGrid

    my $e = Haineko::SMTPD::Relay::SendGrid->new( 
            'username' => 'username',       # API User for SendGrid
            'password' => 'password',       # API Key for SendGrid
            'timeout' => 60,                # Timeout for Furl
            'attr' => {
                'content_type' => 'text/plain'
            },
            'head' => {                     # Email header
                'Subject' => 'Test',
                'To' => 'neko@example.org',
            },
            'body' => 'Email message',      # Email body
            'mail' => 'kijitora@example.jp',# Envelope sender
            'rcpt' => 'cat@example.org',    # Envelope recipient
    );

INSTANCE METHODS ^

sendmail

sendmail() will send email to the specified recipient via specified host.

    my $e = Haineko::SMTPD::Relay::SendGrid->new( %argvs );
    print $e->sendmail; # 0 = Failed to send, 1 = Successfully sent

    print Dumper $e->response; # Dumps Haineko::SMTPD::Response object

getbounce

getbounce() retrieve bounced records using SendGrid API.

    my $e = Haineko::SMTPD::Relay::SendGrid->new( %$argvs );
    print $e->getbounce;    # 0 = No bounce or failed to retrieve
                            # 1 = One or more bounced records retrieved

    print Data::Dumper::Dumper $e->response;
    $VAR1 = bless( {
                 'dsn' => '5.1.1',
                 'error' => 1,
                 'code' => '550',
                 'message' => [
                                '550 5.1.1 <user@example.org>... User unknown '
                              ],
                 'command' => 'POST'
               }, 'Haineko::SMTPD::Response' );

SEE ALSO

http://sendgrid.com/docs/API_Reference/Web_API/

REPOSITORY ^

https://github.com/azumakuniyuki/Haineko

AUTHOR ^

azumakuniyuki <perl.org [at] azumakuniyuki.org>

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: