开发者

Why does Email::MIME split up my attachment?

开发者 https://www.devze.com 2022-12-28 05:54 出处:网络
Why does the attachment(ca. 110KiB) split up in 10 parts(ca. 11KiB) when I send it with this script using Email::MIME?

Why does the attachment(ca. 110KiB) split up in 10 parts(ca. 11KiB) when I send it with this script using Email::MIME?

#!/usr/bin/env perl
use warnings; use strict;

use Email::Sender::Transport::SMTP::TLS; 
my $mailer = Email::Sender::Transport::SMTP::TLS->new(
    host => 'smtp.my.host',
    port => 587,
    username => 'username',
    password => 'password',
);

use Email::MIME::Creator;
use IO::All;
my @parts = (    
    Email::MIME->create(
    attributes => {
        content_type => 'text/plain',
        disposition  => 'inline',
        encoding     => 'quoted-printable',
        charset      => 'UTF-8',
    },
    body => "Hello there!\n\nHow are you?",
    ),
    Email::MIME->create(
    attributes => {
        filename     => "test.jpg",
        content_type => "image/jpeg",
        disposition  => 'attachment',
        encoding     => "base64",
        name         => "test.jpg",
    },
    body => io( "test.jpg" )->all,
    ),
);
my $email = Email::MIME->create(
    header => [ From => 'my@address', To => 'your@address', Subject => 'subject', ],
    parts  => [ @parts ],
);

eval {
    $开发者_StackOverflow社区mailer->send( $email, {
        from => 'my@address',
        to   => [ 'your@address' ],
    } );
};
die "Error sending email: $@" if $@;


I had a similar case using MIME::Lite and Net::SMTP::TLS (using TLS rather than SSL because connection to smtp.gmail.com was not working with SSL) in my Perl script to send email with spreadsheet attachments through a gmail account, whereby the spreadsheet attachments were being broken up into multiple 10kb files.

Solution was to replace Net::SMTP::TLS with Net::SMTP::TLS::ButMaintained, which I hadn't initially seen. Newer TLS module works great.


I can offer you a workaround: using MIME::Lite instead

0

精彩评论

暂无评论...
验证码 换一张
取 消