LukeSmithxyz / mutt-wizard

A system for automatically configuring mutt and isync with a simple interface and safe passwords
GNU General Public License v3.0
2.39k stars 381 forks source link

mailsync does not sync mails in crontab. #929

Closed crissNb closed 1 year ago

crissNb commented 1 year ago

Hello,

whenever I have mailsync in crontab, the program seems to be running via cron job, but it doesn't seem to be actually syncing the mail using mbsync (I'm using IMAP).

mailsync works correctly when it's run in Terminal, also updating my mails.

my crontab -l outputs:

*/10 * * * * /usr/local/bin/mailsync

Which is added via mw -t 10.

I also tried dumping the output of mailsync to a file like so:

*/10 * * * * /usr/local/bin/mailsync > ~/mailsync_dump

And the mailsync_dump outputs: No new mail for me@my.email Even though I should be getting a new email (when I run mailsync manually in Terminal, the output is then 1 new mail for me@my.email). I am positive cron is working properly, because I kept deleting mailsync_dump to verify it's working and I've also waited long enough so that the email is actually gone through.

I'm using macOS 13.3, the shell I've used to run mailsync (and worked correctly) is zsh. What am I missing?

Similar issue #821 was there, but it seems like their problem was not starting the cronie service.

matthew-hennefarth commented 1 year ago

You should also pipe the error of the /usr/local/bin/mailsync into the mailsync_dump file, otherwise it will be trapped by the global "mail" system (see here for better explanation). For example, try changing the mailsync cron to

*/10 * * * * /usr/local/bin/mailsync > ~/mailsync_dump 2>&1

I am going to assume tho that the issue you are having is that the mailsync script is unable to find the mbsync executable due to it being installed in homebrew and is not in the PATH when the cronjob is started. If that is the case, you can edit the cron job to something like

*/10 * * * * source /Users/user/.zshenv && source /Users/user/.config/zsh/.zprofile && /usr/local/bin/mailsync

or to something similar (I am not sure how you have set up your zsh environment).

crissNb commented 1 year ago

I am going to assume tho that the issue you are having is that the mailsync script is unable to find the mbsync executable due to it being installed in homebrew and is not in the PATH when the cronjob is started.

Thanks! This was the problem in my case. It works now!

LeoAdL commented 8 months ago

You can also add directly homebrew to the crontab PATH as follows: https://github.com/LukeSmithxyz/mutt-wizard/issues/973#issuecomment-1892894839

Thanks to @matthew-hennefarth for the solution!