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

Hi all, I'm trying to use a pipe to sendmail to send me a message in the format I have it in the perl script:
use strict; open(SENDMAIL, "| /usr/lib/sendmail -oi -t -fReport_Master") || die "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; To: help@perlmonks.org Subject: Report Submitted by: $name Email: $email Phone: $phone_number Project: $project Date: $submitted Duration of stay: $duration Collaborators: $collaborators EOF ; close(SENDMAIL) || die "Error on close of pipe to mailer: $?";
Hoever, the format doesn't hold when I receive the email. Is there a special trick happening here? Many thanks in advance, Stacy.

Replies are listed 'Best First'.
Re: formatting text with sendmail
by rob_au (Abbot) on May 04, 2002 at 09:16 UTC
    The problem here I suspect isn't so much with Sendmail or your script, but with the mail client you are using to read the mail. A number of mail readers will attempt to render all email by default in a variable-width font, the result in this case is that the vertical alignment between each of the values is lost.

    There are a couple of solutions here - The first is to format your email as a HTML document and send the appropriate Content-Type headers or to modify your mail client settings for the rendering of plain-text emails. With Microsoft Outlook and Outlook Express, the font settings for the rendering of HTML-based and plain-text email can be found in Options under the Mail Format tab. In this location there is a Fonts button which will open another window where the font type for rendering plain-text emails can be set to a fixed width font such as Courier-New - This should solve your issues with formatting of plain-text email within your mail client.

     

Re: formatting text with sendmail
by abstracts (Hermit) on May 04, 2002 at 08:46 UTC
    I can see you're missing the "From: " line in your headers. You need to refer to rfc 822 to see the structure of the headers of email messages. Section 3.4.2 discusses the treatment of white space in the headers and seems like white space is insignificant.

    Also, Mail::Sendmail should be easier to use than rolling your own piped communication with sendmail.

      Thanks for that. I did have the 'From' field covered in the sendmail bit: '-fReport_Master', but I've now put it in with the other headers... Regards, Stacy.