Ansible mail sends weird txt file

A frustrating issue!

When Ansible's mail module sends a weird text file, it's often due to the way the module handles the content of the message. Here are some common causes and solutions:

  1. Unescaped special characters: Ansible's mail module uses the email library to construct the email message. This library can sometimes escape special characters, leading to unexpected output. Try using the escape filter to ensure that special characters are properly escaped:
  1. Incorrect character encoding: The mail module uses the utf-8 encoding by default. If your email body contains non-ASCII characters, you might need to specify a different encoding. You can do this by setting the encoding parameter:
  1. Line breaks and formatting: The mail module can sometimes introduce unwanted line breaks or formatting issues. Try using the indent filter to ensure that your email body is properly formatted:
  1. Content type: The mail module defaults to sending plain text emails. If you need to send HTML emails, you'll need to specify the content_type parameter:
  1. Debugging: If none of the above solutions work, try enabling debug mode for the mail module to see what's going on:

If you're still experiencing issues, please provide more details about your Ansible playbook, the email content, and the error messages you're seeing. I'll do my best to help you troubleshoot the problem!