thezip has asked for the wisdom of the Perl Monks concerning the following question:

G'day monks,

I'm using MIME::Lite to send an email message on a FreeBSD 5.3 server, and I have specified a value for the "From" key, as illustrated in the method below:
sub send { my $self = shift; my $args = shift; my $email = $args->{email} || $self->{EMAIL};; my $subject = $args->{subject} || "Subject not specified"; my $message = $args->{message} || "No message specified"; my $from = $args->{from} || $self->{FROM}; my $msg = MIME::Lite->new( From => $from, To => $email, Subject => $subject, Data => $message ); $msg->send(); }

Unfortunately, when I send the message, it fails to override the sender's name, instead sending the mail literally from "Mail Sender".

How can I override the default behavior of the mailer agent so that I can specify a new sender?

This is certainly something that is configured elsewhere in the OS, but I'm just not sure where to find it...

Where do you want *them* to go today?

Replies are listed 'Best First'.
Re: Cannot seem to override a "From" address using MIME::Lite
by imp (Priest) on Nov 15, 2006 at 20:26 UTC
    I suspect that the source of your problem is that $args{from} is not populated. Inspect the contents using Data::Dumper.

    I tested the provided code locally on OpenBSD 3.5 with perl 5.8.2 and confirmed that the mail was formed correctly, with the provided From address.

      Although I didn't provide the code for the new() method, it is definitely being set to a value. I have also verified this by printing $from on the command-line.

      Is there somewhere else where the value might be defaulted? (ie. in the operating system?)

      Where do you want *them* to go today?
        MIME::Lite sends mails using the local sendmail executable by default, perhaps the implemenation you are using does not allow overriding the From address.

        Try sending the mail using SMTP, as documented here