Mail using Ansible

Hi Guys,
I have written a play for sending an email.
I am able to send an email but in receivers inbox it’s going into spam folder. Can someone please help so that mail will go in inbox.
Thanks in advance.

  • name: Mail sending Using mail Module mail: host: localhost port: 25 to: xyz@example.com subject: Ansible Port Configuration Output body:
     {{ lookup(‘file’, “./output/{{ inventory_hostname }}.txt”) }} 
    delegate_to: localhost

This is a case of "don't shoot the messenger".
Talk to the receiver and find out why it ends up in their spam folder,
and fix that.

Unless your ansible server is set up with SPF DNS records, or going
through an appropriate SMTP services, especially from cloud deployed
Ansible servers, yeah. You're likely to get blocked. The RFC is
https://datatracker.ietf.org/doc/html/rfc7208 .