“Our system has detected that this message is 5.7.1 not RFC 2822 compliant” – Perl and Net::SNMP

Google recently implemented additional SPAM filtering mechanisms whereby they will check whether a message conforms to the IETF RFC 2822 specification (the spec defines the ‘email message standard’). The IETF specification can be viewed here ->

When writing your Perl scripts you might get something back like the following when trying to send a mail to a GMAIL address:

The following message to <someemailaddress @gmail.com> was undeliverable.
The reason for the problem:
5.3.0 - Other mail system problem 550-'5.7.1 [146.26.113.22      11] Our system has detected that this message is\n5.7.1 not RFC 2822 compliant. To reduce the amount of spam sent to Gmail,\n5.7.1 this message has been blocked. Please review\n5.7.1 RFC 2822 specifications for more information. bc3si6864125wjc.158 - gsmtp'
</someemailaddress>

The fix is relatively simple (if it is in fact your problem): specify as many fields as possible when building your message object. Fields like from and subject were considered ‘optional’ in the past (older, pre RFC 2822, spec) but that is no longer true. Even a mail client like Thunderbird or Outlook fills in values (albeit sometimes blank) to make your email go through properly and not be cast out via SPAM filtering

Where your message object might have looked something like this (as per the example on http://perldoc.perl.org/Net/SMTP.html ):

    #!/usr/local/bin/perl -w
    use Net::SMTP;
    $smtp = Net::SMTP->new('mailhost');
    $smtp->mail($ENV{USER});
    $smtp->to(someemailaddress@gmail.com);
    $smtp->data();
    $smtp->datasend("To: someemailaddress@gmail.com\n");
    $smtp->datasend("\n");
    $smtp->datasend("A simple test message\n");
    $smtp->dataend();
    $smtp->quit;

It should now look something like this (note the ‘from’ and ‘subject’ part that was added)

    #!/usr/local/bin/perl -w
    use Net::SMTP;
    $smtp = Net::SMTP->new('mailhost');
    $smtp->mail($ENV{USER});
    $smtp->to(someemailaddress@gmail.com);
    $smtp->data();
    $smtp->datasend("To: someemailaddress@gmail.com\n");
    $smtp->datasend("From: youremailaddress@domain.com\n");
    $smtp->datasend("Subject: A simple test message");
    $smtp->datasend("\n");
    $smtp->datasend("A simple test message\n");
    $smtp->dataend();
    $smtp->quit;

This should fix the issue if GMAIL (or perhaps some other provider) is sending you messages like the one shown above complaining about RFC 2822 compliancy.

Add a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.