/Test cases

How to test email spam score

Learn how to test the SpamAssassin score of an email with Mailosaur

Before you begin

The examples shown below are based on two key assumptions:

  1. That you have already create a basic automated test using our getting started guides.
  2. You have a chosen assertion library that you will use to test the values shown below.

Accessing SpamAssassin results

Allows you to perform a SpamAssassin check against an email. The structure returned matches the spam test object:

const result = await mailosaur.analysis.spam(message.id)

console.log(result.score) // 0.5

result.spamFilterResults.spamAssassin.forEach(r => {
  console.log(r.rule)
  console.log(r.description)
  console.log(r.score)
})
cy.mailosaurGetSpamAnalysis(message.id)
.then((result) => {
    result.spamFilterResults.spamAssassin.forEach((rule) => {
      expect(rule.score).to.be.a('number');
      expect(rule.rule).to.be.ok;
      expect(rule.description).to.be.ok;
    })
})
result = mailosaur.analysis.spam(message.id)

print(result.score) # 0.5

for r in result.spam_filter_results.spam_assassin:
  print(r.rule)
  print(r.description)
  print(r.score)
SpamAnalysisResult result = mailosaur.analysis().spam(message.id());

System.out.println(result.score()); // 0.5

result.spamFilterResults().spamAssassin().forEach(r ->
{
  System.out.println(r.rule());
  System.out.println(r.description());
  System.out.println(r.score());
});
var result = mailosaur.Analysis.Spam(message.Id);
          
Console.WriteLine(result.Score); // 0.5

foreach (var r in result.SpamFilterResults.SpamAssassin) {
  Console.WriteLine(r.Rule);
  Console.WriteLine(r.Description);
  Console.WriteLine(r.Score);
}
result = mailosaur.analysis.spam(message.id)

puts(result.score) # 0.5

for r in result.spam_filter_results.spam_assassin do
  puts(r.rule)
  puts(r.description)
  puts(r.score)
end
$result = $mailosaur->analysis->spam($message->id);

print($result->score); // 0.5

foreach ($result->spamFilterResults->spamAssassin as &$r) {
  print($r->rule);
  print($r->description);
  print($r->score);
}
result, _ := m.Analysis.Spam(message.Id)
fmt.Println(result.Score)

for _, r := range result.SpamFilterResults.SpamAssassin {
  fmt.Println(r.Rule)
  fmt.Println(r.Description)
  fmt.Println(r.Score)
}

See also