0

I have a Perl script which is supposed to send an email, with the content consisting of lines of the form

key = value

The resulting message is sent out by the Perl command

`echo "$msg" | 
   mailx -r $WEBMASTER_EMAIL -s "$field{'subject'}" $field{'email'}\n`;

This works fine when the values are standard ASCII. However, it doesn't work when extended characters are part of any of the values. Instead of text, the email contains an ATT000001.bin file containing the key value pairs.

Is there a parameter I can send to mailx to stop it doing this, or a recommended way I convert my values so that mailx handles them correctly?

Thanks in advance

simbabque
  • 53,749
  • 8
  • 73
  • 136
vogomatix
  • 4,856
  • 2
  • 23
  • 46
  • Is it a hard req to use mailx as opposed to MIME::Lite library? – J Reid Feb 20 '17 at 15:53
  • Sortof, because I'm fixing issues with an old application and I want to make the minimum of changes – vogomatix Feb 20 '17 at 16:29
  • 1
    Minimum fixes way => Take a look at http://stackoverflow.com/q/3120168/2139766 . It suggests way to tweak mailx command line options. If it does not work then use may use `sendmail` program directly. – AnFi Feb 20 '17 at 23:14

1 Answers1

2

I had the exact same problem today, and I found this question via Google. :-)

In my case, I was trying to email the output of a curl command, which unfortunately mixes \r\n and \n. As a result, mailx treats the content as binary and does the weird file attachment thing -- ATT000001.bin.

Assuming you can modify the Perl script, try this:

$msg =~ s/\r\n/\n/g;  # convert Windows newlines to UNIX newlines
$msg =~ s/\r/\n/g;    # convert bare carriage returns to UNIX newlines
`echo "$msg" | 
    mailx -r $WEBMASTER_EMAIL -s "$field{'subject'}" $field{'email'}\n`;

Alternatively, from a shell script (my case), try this:

echo "$msg" | perl -p -e 's/\r\n/\n/g; s/\r/\n/g' | mailx ...

More information from Redhat: https://access.redhat.com/solutions/1136493

kevinarpe
  • 20,319
  • 26
  • 127
  • 154