rjbs / Email-Sender

a perl library for sending email
56 stars 39 forks source link

send mail with attachment like MIME::Lite? #61

Closed yctest9296 closed 6 years ago

yctest9296 commented 6 years ago

Hi, Could you tell me how to use this module to send mail with attachment? Is it possible to be used like the format of MIME::Lite (as below)? Many thanks~

my $email = Email::Simple->create(
      header => [
        To      => '***',
        # cc      => '***',
        From    => '***',
        Subject => "***",
        'Content-Type' => 'multipart/Mixed', #multipart/Mixed;multipart/related
      ],
      body => $some_info ,
    );
$email->attach(
    filename     => "1.txt",
    content_type => 'text/html',
    disposition  => 'attachment',
    name         => "123",
);
yctest9296 commented 6 years ago

I found solution: Email::Sendershould be used along with MIME::Entity if attachment is needed. Module writer mentioned it in description page of MIME::Lite (https://metacpan.org/pod/MIME::Lite). Below code tests ok:

my $top = MIME::Entity->build(
    Type     => "multipart/mixed",
    To      => '***',
    # cc      => '***',
    From    => '***',
    Subject => "***",
);

my $attach_file="./1.txt";
if($attach_file){
    $top->attach(
        Type  => "text/plain",
        Path=>$attach_file,
        Disposition => "attachment",
    );
}
$top->attach(#need to be put in last part
    Type  => "text/html",
    Data=>$html_body,
);
sendmail($top, { transport => $transport });
pali commented 6 years ago

maybe https://metacpan.org/pod/Email::Stuffer ?