Report SPAM to SpamCop Automatically (almost) on Mac OSX

If you’re email provider uses the SpamCop RLB to help block SPAM coming into your account, then you can use the steps below to more easily report SPAM messages you receive and help reduce it.  Setup is a little cumbersome initially, but should be worth it in the end.

In my experience, SpamCop reporting really does work.  I went from getting 500-1,000 SPAM messages per day down to less than a dozen, if that.  It only took a couple days of serious reporting before I started to see a huge difference.

Prerequisites: This tutorial assumes you are using Apple Mail and have Firefox installed.

Setup Steps

1) Create SpamCop Account

Register for a SpamCop account.  Once you complete the registration process, you will be provided an email address that you can use to report your SPAM.  It will probably look something like submit._________@spam.spamcop.net with an alphanumeric string in place of the “_______”.

NOTE: We will need to put your SpamCop username and password in a file on your computer so it’s best to give it a unique password that you don’t use on any other account since this file will be saved in plaintext.

2) Save Python Script

Lucky you, I already did the hard work of writing a Selenium script in Python for you to run.  So just create the python script below called “spamcop-finalize-report.py” on your computer.  For this tutorial, we will assume you created a “python” subfolder in your main ~/Documents directory for this file.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep 

# Open SpamCop
driver = webdriver.Firefox()
driver.get("https://www.spamcop.net/mcgi?action=loginform;returnurl=%2F")

# Login
driver.find_element_by_name("username").send_keys("YOUR_USERNAME")
driver.find_element_by_name("password").send_keys("YOUR_PASSWORD")
driver.find_element_by_name("password").send_keys(Keys.RETURN)

# Report
for x in range(0, 50):
    try:
        print(x+1)
        driver.find_element_by_link_text("Report Now").click()
        subject_wrapper = driver.find_element_by_xpath('//font[@size="2" and @face="courier"]')
        subject = subject_wrapper.find_element_by_xpath('.//strong').text
        driver.find_element_by_xpath('//input[@type="submit" and @value="Send Spam Report(s) Now"]').click()
        print('SPAM Reported: {0}'.format(subject))
        x += 1
        sleep(randint(0,5))
    except:
        try:
            driver.find_element_by_link_text("Report Now")
            continue
        except: 
            print("No more spam to report")
            break        

driver.quit()

Change the text YOUR_USERNAME and YOUR_PASSWORD with the SpamCop username and password created during step #1.

3) Install Selenium WebDriver

Mac OSX already has python built in as well as a package manager called “easy_install” so to complete this step, all you need to do is open up Terminal and run the following command.

sudo easy_install selenium

FWIW… Selenium is what will allow our Python script to automatically open up the browser and finalize the SpamCop report without you having to log in and do it.

If you already have selenium installed or need to update it, just run the following command. You may need this if Firefox releases and update that breaks your selenium script (which they like to do every now and then).

sudo easy_install --upgrade selenium

4) Setup AppleScripts

We will need two AppleScripts to automate reporting.  Download each file, extract, and save the .scpt files in the root “/Library/Scripts/Mail Scripts/” directory (if you don’t already have a “Mail Scripts” directory, just create one).

5) Setup Keyboard Shortcuts for the AppleScripts

To more easily run these scripts, we can setup keyboard shortcuts by downloading a little program call “Fast Scripts”.

  • Download Fast Scripts and Install
  • Open up the Fast Scripts “Preferences”
  • Click the “Script Shortcuts” tab
    Screenshot of Fast Scripts Preferences for Keyboard Shortcuts
  • Expand “/Library/Scripts” and then “Mail Scripts” and you should now see your two Apple Script files
  • Double click on each of your scripts and then press the keyboard shortcut you want to use.  In my case I used…
    • Report_to_SpamCop: Ctrl + Cmd + R
    • Finalize_Report_to_SpamCop: Ctrl + Opt + Cmd + R

Actually Reporting SPAM

Now that you have everything setup, to actually report your SPAM, here are the steps…

  • When in your Mail program, highlight the messages you want to report as SPAM
  • Press Ctrl+Cmd+R (the shortcut you set up for your Report_to_SpamCop script)
  • Wait for SpamCop to email you back with a message like “[SpamCop] has accepted X emails for processing”
  • Press Ctrl+Opt+Cmd+R (the shortcut you set up for your Finalize_Report_to_SpamCop script)

Personally I like to mark all my SPAM as Junk first in Mail then go through my Junk folder to report it.  Once done you can just use the keyboard shortcut Opt+Cmd+J to erase all the mail in your Junk folder.

Important Notes

  • Emailed reports to SpamCop have a maximum size and attachment count.  The most common one you will hit is the max size of 50 KB.  So when you are reporting multiple emails, just tally up the total of each email and try and keep it under 50 KB for each report).  Per SpamCop…

    You may attach multiple spams to a single submission. You should not exceed 20 spams attached to a submission. The maximum size for the overall submission must not exceed 50 KB.

  • Be careful to only report actual SPAM messages.  SpamCop is a great tool for helping cut down your SPAM, but if you report messages that are not SPAM you could lose your SpamCop account as well as blocking actual messages from getting to recipients for anyone in the world using SpamCop.  This is also why I don’t recommend fully automating your reporting because you do not want to accidentally report the wrong messages.  Use with caution.
0 0 vote
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mat Kramer
Mat Kramer
3 years ago

Thanks for the work you’ve done on this and the great instructions!

I installed everything as above, but I am still getting a few errors when I try to report:

——-
$ cowsay ‘Running your SpamCop script now. Moo!’
-bash: cowsay: command not found
$ python ~/Documents/python/spamcop-finalize-report.py
Traceback (most recent call last):
File “/Users/matkramer/Documents/python/spamcop-finalize-report.py”, line 6, in
driver = webdriver.Firefox()
File “/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py”, line 144, in __init__
self.service.start()
File “/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/common/service.py”, line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.
——-

It looks like the solution might be here?
https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path

James A
James A
2 years ago

I am also getting the same:

python ~/Documents/python/spamcop-finalize-report.py
Traceback (most recent call last):
File “/Users/*/Documents/python/spamcop-finalize-report.py”, line 6, in
driver = webdriver.Firefox()
File “/Library/Python/2.7/site-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py”, line 144, in __init__
self.service.start()
File “/Library/Python/2.7/site-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/common/service.py”, line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.