in reply to How to send email using Email::MIME & Email::Sender::Simple?

The following code, which is distilled from your example, works fine for me. Just a guess, perhaps you have an old version of one of the modules in one of your many use lib directories? Also, since you seem to be using PAR (I think?), have you tried running the script outside of that?

use warnings; use strict; use Email::MIME; use Email::Sender::Simple 'sendmail'; use Email::Sender::Transport::SMTP; my $message = Email::MIME->create( header_str => [ From => 'test@example.com', To => $ENV{USER}.'@localhost', Subject => 'Happy birthday!', ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', }, body_str => "Happy birthday to you!\n", ); sendmail($message, { from => 'test@example.com', transport => Email::Sender::Transport::SMTP->new( { host => 'localhost', port => 25 }), });

Replies are listed 'Best First'.
Re^2: How to send email using Email::MIME & Email::Sender::Simple?
by Magkumar (Novice) on May 03, 2020 at 16:30 UTC

    Yes I'm using PAR indeed, below is the command I'm using to pack the script into executable. The script is running fine as .pl & .exe in my local system. However when I try to distribute the same exe to a Win Server machine, it fails with the mentioned error.

    pp -u -o test.exe test.pl

    Also, I did try using Email::Stuffer, but it is again in turn invoking Email::Sender::Simple , which gives me the same error. Perhaps the way I'm packing the script to executable is wrong?

      Although I'm not an expert on PAR, I still suspect it has something to do with all those use lib dirs. I suggest you inspect all of the directories listed in @INC when the program runs (e.g. print "<<$_>>\n" for @INC;) for which versions of Email::Sender etc. are installed there. Also, I would suggest just removing all of the use lib dirs from the script, as I don't see a good reason why all the C:\Strawberry ones are there in the first place (and "C:\\Strawberry\\perl\\vendor\\lib\\Email" is almost certainly wrong), and just working with Perl's defaults - that's what cpanm will use as well.

        Sure thing, will remove all the explicit directory paths. Will get back if I find something interesting. Thanks a lot!

Re^2: How to send email using Email::MIME & Email::Sender::Simple?
by Magkumar (Novice) on May 03, 2020 at 16:32 UTC

    Yes I'm using PAR indeed, below is the code I'm using to pack the script into executable. The script is running fine as .pl & .exe in my local system. However when I try to distribute the same exe to a Win Server machine, it fails with the mentioned error.

    pp -u -o test.exe test.pl

    Also, I did try using Email::Stuffer, but it is again in turn invoking Email::Sender::Simple , which gives me the same error. Perhaps the way I'm packing the script to executable is wrong?