Mail: all accounts set to offline but still receive emails

emailmail.app

In Mac Mojave, when I want to focus on work then I switch all email accounts in Mail.app to offline mode. I could of course close the application, for better focus, but can not do it since I need to find reference material in some email folders. But the thing is, even in all accounts are set to offline, I am still getting new emails. How can I fix this?

Best Answer

  • You can define your firewall to block mail.app when activated, then toggling it on/off when needed.

  • You could also use another app (like Radio Silence) to only block mail.app and keep your firewall running (and I'd personnaly go with that solution). I don't believe Radio Silence has a shortcut but it's really easy to set up & use (literraly launch Radio Silence, drag Mail.app into it and toggle on/off button when needed).


If you prefer to set up an automator script to enable/disable the firewall to block mail.app

First of all set the firewall to block Mail.app:

  1. Go to System Preferences -> Security and Privacy -> Firewall
  2. Click on the lock on the bottom left to make change
  3. Click on "Firewall Option..."
  4. Click on + and add "Mail.app", then choose "block incoming connections" (like transmission in the picture below)

enter image description here

After that, you can use this script to toggle the firewall:

(this AppleScript allows a user to turn on or off the built in firewall. The script reads and then displays the current state and then presents an option for changing that status. The change happens immediately but the Systems Preference pane needs to be closed out and reopened in order to visually see that change. I found it here)

set firewallState to do shell script "defaults read /Library/Preferences/com.apple.alf globalstate"
if firewallState = "0" then
    set firewallStatus to "The firewall is currently set to off (or allow all incoming connections)"
else if firewallState = "1" then
    set firewallStatus to "The firewall is currently set to allow access for specific services and applications"
else if firewallState = "2" then
    set firewallStatus to "The firewall is currently set to allow only essential services"
end if

#change status of the firewall: 0=off 1=on for specific services and 2=on for essential services

display dialog firewallStatus & return & return & "Do you want to enable the firewall?" buttons {"Cancel", "Turn Firewall Off", "Turn Firewall On"} default button 1 with icon 2
set the userChoice to the button returned of the result

if the userChoice is "Turn Firewall Off" then
    do shell script "defaults write /Library/Preferences/com.apple.alf globalstate -int 0" with administrator privileges
end if

if the userChoice is "Turn Firewall On" then
    do shell script "defaults write /Library/Preferences/com.apple.alf globalstate -int 1" with administrator privileges
end if

Finally, you can save it into an .command and active it by a click or use terminal with osascript /Users/USERNAME/Desktop/YOURSCRIPT.applescript

Or set up Automator to create a Mac Application that you can double click, add to the dock, etc.:

  1. Open Automator application
  2. Choose "Application" type
  3. Type "run" in the Actions search box
  4. Double click "Run Shell Script"
  5. Click the Run button in upper right corner to test it.
  6. File > Save to create the Application.

enter image description here