If you use the TWiki::cfg{MailProgram} with sendmail, the mail sender in smtp envelope (smtp server) will taken from system. If you use for example "nullmailer" as injector you will get sometimes something like "unknown@my.domain" even if you have set WIKIWEBMASTER in
TWikiPreferences.
You could use the sendmail option -f to set the sender also
This patch will modify Net.pm and take the envelope for "From" in the same manner like the _sendEmailByNetSMTP procedure will do. Maybe it is interesting for someone.
patch:
--- lib/TWiki/Net.pm 2006-09-04 09:03:18.000000000 +0200
+++ lib/TWiki/Net.pm 2006-10-28 01:22:19.000000000 +0200
@@ -226,12 +226,31 @@
sub _sendEmailBySendmail {
my( $this, $text ) = @_;
+ my $from = '';
+
# send with sendmail
my ( $header, $body ) = split( "\n\n", $text, 2 );
+ my @headerlines = split( /\r?\n/, $header );
$header =~ s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
$text = "$header\n\n$body"; # rebuild message
- open( MAIL, '|'.$TWiki::cfg{MailProgram} ) ||
+ # extract 'From:'
+ my @arr = grep( /^From: /i, @headerlines );
+ if( scalar( @arr ) ) {
+ $from = $arr[0];
+ $from =~ s/^From:\s*//io;
+ $from =~ s/.*<(.*?)>.*/$1/o; # extract "user@host" out of "Name <user@host>"
+ }
+ unless( $from ) {
+ # SMELL: should be a TWiki::inlineAlert
+ die "ERROR: Can't send mail, missing 'From:'";
+ }
+
+ # untain data inside from address
+ if ($from =~ /^([-\@\w.]+)$/) { $from = $1; } else
+ { die "ERROR: Bad data in 'From:' [$from]"; }
+
+ open( MAIL, '|'.$TWiki::cfg{MailProgram}.' -f "'.$from.'"' ) ||
die "ERROR: Can't send mail using TWiki::cfg{MailProgram}";
print MAIL $text;
close( MAIL );
This is an excellent idea, but has been missed due to being set to "Waiting for Feedback". Resetting to Normal/Actioning, as I consider this to be a bug. Anyone can do it (it's just a simple case of applying the patch).
CC
On reflection I realised this can be done trivially by changing the
{MailProgram}
command line in
configure
to include the -f option.
Discarded.
CC
Hi Crawford, thanx for reflecting this item again, btw. could you explain how to add this to
MailProgram config option? I did not realized this, of course you could add the "-f" option but how could I append the mails from address to this option dynamically with the current senders address?
Thanx for an answer
ThF
p.s.: I hope it is okay to set this again to state "new", I am not sure if will get the conversation otherwise.
You can't, but since TWiki only ever sends mails from TWIKIWEBMASTER it doesn't matter.
My view is that TWiki is a wiki, not a mail tool
If you want to debate this further, please open a brainstorming topic in Codev.
CC