Nile::Plugin::Email - Email plugin for the Nile framework.


    $email = $app->plugin->email;
    # or create new object
    #$email = $app->plugin->email->new;

        from    => '',
        to      => '',
        subject => 'Happy birthday Ramy',
        body    => 'Hello Ramy, Happy new year Ramy',
        type    => 'html', # 'html' or 'text' message type
        attach  => '/path/to/attachment', # optional attachment file


Nile::Plugin::Email - Email plugin for the Nile framework.

This plugin build on the top of Email::Sender::Simple module which supports any transporter like Sendmail, SMTP etc.

Plugin configuration can be set in the config file under the plugin section.

Example plugin configuration for SMTP transporter:


            <helo>Hello from loclahost</helo>


Example plugin configuration for Sendmail transporter:




If no configuration found, the module will search for Sendmail program and use it, if not found it will try to connect to local SMTP server.

You also can set the transporter programmatically using the method "transport" below.


Send email with optional attachments quickly:

        from    => '',
        #from    => '"Ahmed Elsheshtawy" <>',
        to      => '',
        subject => 'Happy birthday Ramy',
        body    => 'Hello Ramy, Happy new year Ramy',
        type    => 'html', # 'html' or 'text' message type, default 'html'
        attach  => '/path/to/attachment',   # optional attachment file

Send email with many options:


        from        => '',
        to      => '',

        cc      => ['', '', ''],
        bcc     => ['', '', ''],

        subject => 'Happy birthday Ramy',
        # optional headers
        sender      => '', # set to the 'from' if not set
        #'Return-Path'  =>  '', # set to the 'from' if not set
        #'Reply-To'     =>  '', # set to the 'from' if not set
        #'X-Mailer'     =>  'Nile',
        #'X-Priority'   =>  3, # highest => 1, high => 2, normal => 3, low => 4, lowest => 5
        #Date       =>  email_date(), # automatically set to current date and time
        #Comments   =>  '',
        #Encrypted  =>  '',
        #References     =>  '',
        #'Message-ID'   =>  '',
        #'MIME-Version' =>  '',
        #Organization   =>  'Mewsoft',
        #multipart  => 'related',

        type        => 'html', # 'html' or 'text' message type, default 'html'

        # optional raw headers overried above and used as is
        header      => {
            "X-Mailer"          => '',
            "X-Accept-Language" => 'en',
        # attachments
        attach      => [
                Path => "/path/to/attachment4",
                # Mime::Entity options.
                Id => "...",

Set the email components one by one for more control:

    $email->cc(['', '']);
    $email->bcc(['', '']);
    $email->subject('Happy birthday');
    $email->body('Hello Ramy, Happy new year');
    # send the email


    $from = $email->from;

Sets or returns the from email address.


    $to = $email->to;

Sets or returns the to email address.


    # if not set, the from address will be used
    $sender = $email->sender;

Sets or returns the sender email address.


    $email->cc('', '');
    @cc = $email->cc;

Sets or returns the cc email addresses.


    $email->bcc('', '');
    @bcc= $email->bcc;

Sets or returns the bcc email addresses.


    $subject = $email->subject;

Sets or returns the subject.


    $body = $email->body;

Sets or returns the body.


    # default is 'quoted-printable'
    $encoding = $email->encoding;

Sets or returns the encoding. Standard encodings are '7bit', '8bit', 'base64', 'binary', 'quoted-printable'. Non-standard encodings are 'binhex', 'binhex40', 'mac-binhex40', 'mac-binhex', 'x-uu', 'x-uuencode'.

Encoding auto detected if not set.


    # $format = 'flowed';
    $format = $email->format;

Sets or returns the format.


    # default $charset = "UTF-8";
    $charset = $email->charset;

Sets or returns the charset.


    # default is "mixed" for "multipart/mixed"
    $multipart = $email->multipart;

Sets or returns the multipart.


    $email->header->{$name} = $value;
    $value = $email->header->{$name};

Sets or returns the header entries.


    # html email message
    # text/plain email message

Sets or returns the message content type.



Sets or returns the header X-Mailer.



            Path => "/path/to/attachment4",
            # Mime::Entity options
            Id => "...",

Attach files to the email message.


    $email->transport($transport, %options);
    # set transport to Sendmail program, path auto detected

    # set transport to Sendmail program, specify path to it
    $email->transport('Sendmail', { sendmail => '/usr/sbin/sendmail' });
    # set transport to SMTP with options
    $email->transport("SMTP", {
        host => '', # the name of the host to connect to; defaults to localhost
        ssl => 0, # if true, connect via SSL; defaults to false
        port => 25, # port to connect to; defaults to 25 for non-SSL, 465 for SSL
        timeout => 180, # maximum time in secs to wait for server; default is 120
        sasl_username => '', # the username to use for auth; optional
        sasl_password => '', # the password to use for auth; required if username is provided
        allow_partial_success => 0, # if true, will send data even if some recipients were rejected; defaults to false
        helo => '', # what to say when saying HELO; no default
        #localaddr => 'localhost', # local address from which to connect
        #localport =>'1234', # local port from which to connect
    # custom transport
    #$transport = MyTransport->new();
    $email->transport($transport, %options);

Set the email transporter class. Can be Email::Sender::Transport subclass name like Sendmail, SMTP, etc or Email::Sender::Transport type object.

To find available transporters, search cpan for Email::Sender::Transport



Send the email with current settings. This method is called automatically by the method email to send the email.


This project is available on github at


Please visit the project's homepage at


Source repository is at


See Nile for details about the complete framework.


Ahmed Amin Elsheshtawy, احمد امين الششتاوى <> Website:


Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى,,,

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