这对我有用,几乎涵盖了所有硬反弹。这是 Perl,但您可以使用这个 Regex 非常安全地自行开发。
my $content = 'EMAIL MESSAGE HEADER AND BODY';
if (
$content =~ m/Status: 5\.\d\.\d/i || # Any 5xx error
$content =~ m/Action: Failed/i ||
$content =~ m/Reason: 5\.\d\.\d/i || # Any 5xx error
$content =~ m/MAILER-DAEMON/i ||
$content =~ m/Mailbox does not exist/i ||
$content =~ m/No Such User/i ||
$content =~ m/Delivery to the following recipients failed/i ||
$content =~ m/Recipient address rejected/i ||
$content =~ m/Host or domain name not found/i ||
$content =~ m/mailbox unavailable/i
){
# Extract email address from FINAL-RECIPIENT header:
$content =~ s/^.*?final-recipient:\s?rfc822;?\s?([^\n]+).*?$/$1/is;
}