• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

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.


--- 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).


On reflection I realised this can be done trivially by changing the {MailProgram} command line in configure to include the -f option.



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 smile

If you want to debate this further, please open a brainstorming topic in Codev.


Summary Setting MAIL-ENVELOPE sender when using /usr/bin/sendmail as MailProgram
ReportedBy TWiki:Main.ThomasFreudenberg
Codebase 4.0.4
SVN Range

AppliesTo Engine

Priority Normal
CurrentState No Action Required


TargetRelease n/a
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r6 - 2006-12-19 - CrawfordCurrie
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback