Plain text emails displayed as attachment on some email clients

68 views Asked by At

The email can be viewed normally using some email clients (Evolution, Thunderbird), but with other clients (e.g., GMX) the body of the message remains empty and an attachment containing the body of the message is sent.

I would like to know how I can prevent this from happening, since the message is intended to be read by humans and having the body in an attachment is weird.

    my $ServerName = "";

    my $from_address = '';
    my $to_address   = '';
    my $subject      = 'MIME Test: Text';
    my $mime_type    = 'text';
    my $message_body = "This is a test.\n";
    # Create the initial text of the message
    my $mime_msg = MIME::Lite->new(
    From    => $from_address,
    To      => $to_address,
    Subject => $subject,
    Type    => $mime_type,
    Data    => encode("utf8",$message_body)

    ) or die "Error creating MIME body: $!\n";

    # encode body of message as a string so that we can pass it to Net::SMTP.

    $message_body = $mime_msg->body_as_string();

    # Let MIME::Lite handle the Net::SMTP details
    MIME::Lite->send( 'smtp', $ServerName,);# AuthUser => $user, AuthPass => $pass );
    $mime_msg->send() or die "Error sending message: $!\n";
1

There are 1 answers

0
Borodin On BEST ANSWER

I think this is the closes thing you're going to get to an answer

The documentation for MIME::Lite says this

MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.

The "current maintainer" is the inimitable Ricardo Signes and I suggest you follow his advice