Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

email submission

by Anonymous Monk
on Nov 24, 2000 at 17:12 UTC ( [id://43211]=perlquestion: print w/replies, xml ) Need Help??

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

Is there a way of forcing the From field to accept an email address which the user has defined rather than the server mail address?

I would appreciate any help you can give.
Thanks.

Replies are listed 'Best First'.
Re: email submission
by merlyn (Sage) on Nov 24, 2000 at 18:07 UTC
    There are so many variables to this it'd be hard to answer your question without knowing what MTA you're using. Also, if you use SMTP directly, you can specify any headers you choose. The Net::SMTP module will let you do that, and there are some others that have a nicer interface that sit on top of Net::SMTP.

    -- Randal L. Schwartz, Perl hacker

Re: email submission
by kilinrax (Deacon) on Nov 24, 2000 at 17:56 UTC
    Check that 'www-data' (or whichever user is sending the mail) is allowed by your MTA to set the 'From:' field. For instance, if you're using exim, add the user name to the 'trusted users' field of '/etc/exim.conf', e.g:
    trusted_users = mail:www-data
    If you're not using exim, then I'm sorry I can't be more help, but there will probably be a similar configuration option somewhere, which I'd guess should be covered in the documentation of whatever you're using ;-)

    Update: Thought you might find the following code useful to check yours against or even adapt to your purposes ;-)
    #!/usr/bin/perl -w use strict; use Mail::Mailer; use Getopt::Std; use vars qw( %opts $line $user $body ); getopts('f:t:s:h', \%opts); $user = getpwuid($<); sub usage() { print <<EOF; Usage: $0 [options] Example: $0 -t root\@jerkcity.com -f die.puny\@earthling.net -s \'Your + comic is the wierdest thing _ever_\' Synopsis: sends mail to the specified address -h : displays this help screen -t ADDRESS : address to mail to -f ADDRESS : address to mail from (default is your user name: \'$user\ +') -s SUBJECT : subject of the mail If no flags are given, then the first argument given is assumed to be +the address to mail to, or if no options are given, this help screen +is displayed. EOF exit; } if ($opts{'h'}) { usage(); } if (!$opts{'t'}) { if ($ARGV[0]) { $opts{'t'} = $ARGV[0]; } else { die "You must enter an address to mail to. See $0 -h for help on u +sage."; } } if (!$opts{'f'}) { $opts{'f'} = $user; } if (!$opts{'s'}) { $opts{'s'} = 'No subject'; } print "Enter body of message, use a single \'.\' on a line to finish.\ +n"; while ($line = <STDIN>) { last if ($line =~ /^\.$/); $body .= $line; } sendmail ($opts{'f'}, $opts{'t'}, $opts{'s'}, $body); print "Mail Sent.\n"; exit; sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new('sendmail'); }; if ($@) { warn "Couldn't send mail: $@"; } else { $mailer->open({ To => $to, From => $from, Subject => $subject }); print $mailer $body; unless (close ($mailer)) { warn "Couldn't close mailer: $!"; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://43211]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found