App-mailmake

 view release on metacpan or  search on metacpan

scripts/mailmake  view on Meta::CPAN

    subject         => { type => 'string',  alias => [qw( s )] },
    header          => { type => 'array' },    # repeatable: Name:Value

    # Body
    plain           => { type => 'string' },   # plain-text body (literal)
    plain_file      => { type => 'file' },     # plain-text body from file
    html            => { type => 'string' },   # HTML body (literal)
    html_file       => { type => 'file' },     # HTML body from file
    attach          => { type => 'file-array' },         # file attachments
    attach_inline   => { type => 'file-array' },         # inline (related) parts
    charset         => { type => 'string',  default => 'UTF-8' },

    # Output - print to stdout instead of sending
    print           => { type => 'boolean', default => 0 },

    # SMTP delivery
    smtp_host       => { type => 'string',  alias => [qw( host H )] },
    smtp_port       => { type => 'integer', alias => [qw( port P )] },
    smtp_user       => { type => 'string',  alias => [qw( user U )] },
    smtp_password   => { type => 'string',  alias => [qw( password )] },
    smtp_tls        => { type => 'boolean', default => 0 },  # SMTPS port 465

scripts/mailmake  view on Meta::CPAN

                    _die( "Error setting header $1 with value $2: ", $mail->error );
            }
            else
            {
                _message( 1, "Warning: ignoring malformed --header value: <orange>$hdr</>" );
            }
        }
    }

    # Body
    my $charset = $opts->{charset} // 'UTF-8';

    if( $opts->{plain_file} )
    {
        my $f = $opts->{plain_file};
        _die( "plain-file \"$f\" does not exist." ) unless( $f->exists );
        my $text = $f->load_utf8 ||
            _die( "Cannot read plain-file \"$f\": ", $f->error );
        $mail->plain( $text, charset => $charset ) || _die( $mail->error );
    }
    elsif( defined( $opts->{plain} ) && length( $opts->{plain} // '' ) )
    {
        _message( 3, "Setting body to '", $opts->{plain}, "'" );
        $mail->plain( $opts->{plain}, charset => $charset ) ||
            _die( "Error setting plain body: ", $mail->error );
    }

    if( $opts->{html_file} )
    {
        my $f = $opts->{html_file};
        _die( "html-file \"$f\" does not exist." ) unless( $f->exists );
        my $html = $f->load_utf8 ||
            _die( "Cannot read html-file \"$f\": ", $f->error );
        $mail->html( $html, charset => $charset ) || _die( $mail->error );
    }
    elsif( defined( $opts->{html} ) && length( $opts->{html} // '' ) )
    {
        $mail->html( $opts->{html}, charset => $charset ) || _die( $mail->error );
    }

    if( $opts->{attach} && @{$opts->{attach}} )
    {
        _message( 3, "Processing ", scalar( @{$opts->{attach}} ), " attachments." );
        foreach my $f ( @{$opts->{attach}} )
        {
            _message( 3, "Attaching file $f" );
            _die( "Attachment file \"$f\" does not exist." ) unless( $f->exists );
            $mail->attach( path => "$f" ) || _die( $mail->error );

scripts/mailmake  view on Meta::CPAN

HTML body loaded from a file.

=item B<--attach> FILE [FILE ...]

File attachment(s), added as C<multipart/mixed> parts (repeatable).

=item B<--attach-inline> FILE [FILE ...]

Inline attachment(s), added as C<multipart/related> parts, intended for embedding images in HTML (repeatable).

=item B<--charset> NAME

Character set for text bodies. Default: C<UTF-8>.

=back

=head2 Output

=over 4

=item B<--print>



( run in 0.573 second using v1.01-cache-2.11-cpan-39bf76dae61 )