linuxbashemailmailxautomic

In Automic 12 bash, special characters in mailx body result in body being attached as a binary file


I am trying to send an email using mailx through Automic Workload Automation 12.0's bash jobs. The message needs to have a special character, in this case the percent sign "°".

The message should have the body This is the ° sign., for this example.

I am using this code to send the message. printf '\xB0' prints the ° sign.

(
  printf 'This is the '
  printf '\xB0'
  printf ' sign.'
) | mailx [etc]

If I copy and paste this directly into a bash terminal, the email sends fine with the special character printed in the message body.

However, when I use the same code in Automic bash jobs, the email body is blank. There is a file attached, named ATT00001.bin. If I open ATT00001.bin using notepad.exe, the file contains the text that should have been in the body, This is the ° sign. With the characters printed exactly as they should be in the body.

The following when used in Automic results in a message being sent with the correct body. No files are attached. So it seems clear that the special character is causing this issue with Automic.

(
  printf 'This is the '
  printf 'placeholder'
  printf ' sign.'
) | mailx [etc]

Does anyone know why this happens, or how to resolve it?


Solution

  • Mailx is a evolved MUA. For just sending a mail, if you use sendmail, you could build your own mail header:

    /usr/sbin/sendmail destuser@desthost <<eomail
    To: destuser@desthost
    Subject: Any interesting thing
    MIME-Version: 1.0
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: 8bit
    
    This is the ° sign
    eomail
    

    Or you could use html encoding:

    /usr/sbin/sendmail destuser@desthost <<eomail
    To: destuser@desthost
    Subject: Any interesting thing
    MIME-Version: 1.0
    Content-Type: text/html; charset="ASCII"
    Content-Transfer-Encoding: 8bit
    
    <html><body>This is the &deg; sign</body></html>
    eomail
    

    Care, use only ASCII characters there!