postfix-users

Re: postfix sendmail and Mime

Subject: Re: postfix sendmail and Mime
From: Vance Wheelock <vance AT csh.rit DOT edu>
To: postfix-users AT postfix DOT org
Date: Wed, 08 Aug 2007 18:58:05 -0400
Wietse Venema wrote:
Vance Wheelock:
  
The output message looks like:

======================================================================
From: xxx AT xxx DOT com
To: xxxx AT xxxxx DOT net
Subject: Teleblend test
References: <00e501c7d9e4$03a64e30$0200810a AT xxxx DOT net>
In-Reply-To: <00e501c7d9e4$03a64e30$0200810a AT xxxxx DOT net>
MIME-Version: 1.0
Content-Type: multipart/alternative;
  boundary="------------060108060008080501030900"
Message-Id: <20070808174614.4B8B757E78 AT xxxxx DOT com>
Date: Wed,  8 Aug 2007 13:46:14 -0400 (EDT)


This is a multi-part message in MIME format.
--------------060108060008080501030900
    

That should render OK with MIME-aware software.

  
I agree with you 100%, unfortunately crappy Microsoft Outlook will not render that properly and unfortunately, a high percentage of users use Outlook. I use Thunderbird and it renders just fine, it is just that most of the people will be using this vacation script also use Outlook.

  
The Message-Id: and Date: lines are appended by postfix's sendmail (as
far as I can tell). The two lines get appended at the very first empty
line. In this case since I do not have an extra cr/lf under the
"Mime-Version 1.0" line and my body is directly below the "Mime-Version
1.0" line, the two lines get pasted into the "body" of my message where
it finds it's first empty lines. The $body string starts with the lines

Content-Type: multipart/alternative;
  boundary="------------060108060008080501030900"

and then after this is a new line, and that is where the two lines are
being appeneded plus two cr/lf lines.

So I thought I could append an extra newline after the "Mime-Version
1.0" line and it would work.
    

That definitely screws up the mail. The Content-Type:  is no longer
part of the message headers, and thus your MIME boundaries no longer
work.

If you want to write MIME formatted mail, you need to study the
MIME RFC documents.

	Wietse
  
This is has something to do with the postfix's sendmail executable and how it appends headers which are missing. In this case the Message-Id: and Date: lines.

Given the following perl code: (this is from postfixadmin's vacation.pl) I have edited it slightly from my last message (removing the is_html code because it wasn't necessary)

==========================
sub do_mail {
   my ($from, $to, $subject, $body, $orig_msgID) = @_;
   # clean up the email address since we pass it to the commandline
   #To use HTML the message mus contain the whole MIME encapsulated part
   my $fromemail = $from;
   if ($fromemail =~ /([\w\-.%]+\@[\w.-]+)/) { $fromemail = $1; }
   open (MAIL, "| $sendmail -t -f \"$fromemail\"") or die ("Unable to open sendmail");
   print MAIL "From: $from\n";
   print MAIL "To: $to\n";
   print MAIL "Subject: $subject\n";
   if ( $orig_msgID ) {
        print MAIL "References: $orig_msgID\n";
        print MAIL "In-Reply-To: $orig_msgID\n";
   }
   print MAIL "X-Loop: Postfix Admin Virtual Vacation\n";
   print MAIL "$body";
   close (MAIL) or die ("Unable to close sendmail");
}
=============================================

Outlook will not render the output corectly. However if I switch the executable to work with sendmail's sendmail executable. The sendmail executable work's as expected and the Message-Id and Date lines appear near the top of the header and are not appeneded at the end.

As in the previous messages in this thread, it appears that postfix's sendmail at least in the version I'm using postfix-2.2.11 it wants to add missing header lines to the end of the header (or first available empty line in the text it is passed). Not only that,  it seams to want to append two crlf's after it appends those two lines. When I test with sendmail's

If I compose a simple text message for the body with no Mime or anything else I still get the two lines appended. Here I use the perl code above and have nothing in the body except "Hello World". I still see Message-Id and Date: lines appended with 2 crlf after them.

Postfix Sendmail:
==========================
From: xxx AT xxx DOT net
To: xxx AT xxxx DOT com
Subject: Test
References: <019b01c7da07$de48fce0$0200810a AT xxx DOT net>
In-Reply-To: <019b01c7da07$de48fce0$0200810a AT xxxx DOT net>
X-Loop: Postfix Admin Virtual Vacation
Message-Id: <20070808220253.7523D57E47 AT xxx.xxxx DOT com>
Date: Wed,  8 Aug 2007 18:02:53 -0400 (EDT)

Hello World
==========================
Using sendmail's executable with everything the same I get:
======================================
Date: Wed, 8 Aug 2007 18:30:10 -0400
Message-Id: <l78MUAfw005752 AT xxx.xxxx DOT com>
From: xxxxx AT xxxxxx DOT net
To: vwheelock AT usacsp DOT com
Subject: Test
References: <46BA43F6.9030200 AT xxxx DOT com>
In-Reply-To: <46BA43F6.9030200 AT xxxx DOT com>
X-Loop: Postfix Admin Virtual Vacation

Hello World
=============================================

Nowhere did I put the "Message-Id" or "Date" lines in the message, so Postfix sendmail as well as Sendmail's sendmail appended them, just in different locations. For text based messages, this is fine, but the problem is when you need to add MIME (believe me I know how to construct a proper MIME message) and view in Outlook. The lines are appended in my opinion incorrectly. This is my complaint and probably won't go anywhere. Since I can make this work with sendmail's version,  I can do that.

However, if someone can point to a small perl script without extra libraries that does the simplest MIME encoded message, I would love to see it work with Postfix's sendmail and render fine in Outlook.
<Prev in Thread] Current Thread [Next in Thread>