我试图让离线映射在OSX上使用launchd在后台运行。
这是我的褶皱:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/offlineimap</string>
<string>-u</string>
<string>quiet</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/Users/Andy/.Mailder/offlineimap_err.log</string>
<key>StandardOutPath</key>
<string>/Users/Andy/.Mailder/offlineimap.log</string>
</dict>
</plist>这将加载并运行,但是我的日志显示offlineimap遇到了一个错误:
OfflineIMAP 6.7.0
Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
ERROR: No module named keyring
ERROR: Exceptions occurred during the run!
ERROR: No module named keyring为了避免在我的.offlineimaprc中使用明文密码,我使用了描述为这里的python方法。
当我从终端运行offlineimap时,它可以正常工作,并且我可以使用python密钥环导入我的密码,没有问题。类似地,当我将offlineimap作为一个cron作业运行时,这似乎也是没有意外的。但是,cron在OSX上是不推荐的,所以我更喜欢使用launchd。
我的.offlineimaprc的相关部分:
[general]
accounts = personal, work
maxsyncaccounts = 3
pythonfile = /Users/Andy/offlineimap.py
[Repository personalRemote]
type = IMAP
remotehost = myhost.com
remoteuser = myalperson@email.com
remotepasseval = keyring.get_password('email', 'personal')
[Repository workRemote]
type = IMAP
remotehost = myhost.com
remoteuser = mywork@email.com
remotepasseval = keyring.get_password('email', 'work')我的offlineimap.py文件
#!/usr/bin/python
import keyring发布于 2016-05-28 00:36:18
要回答错误:
$sudo pip install keyring如果这对你不管用,
0)在密钥链中创建密码,就像已完成的在这里检索密码部分
1)创建文件
$touch ~/offlineimap.pyofflineimap.py
#!/usr/bin/python
import re, subprocess
def get_keychain_pass(account=None, server=None):
params = {
'security': '/usr/bin/security',
'command': 'find-internet-password',
'account': account,
'server': server,
'keychain': '/Users/${USER}/Library/Keychains/login.keychain',
}
command = "sudo -u ${USER} %(security)s -v %(command)s -g -a %(account)s -s %(server)s %(keychain)s" % params
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
outtext = [l for l in output.splitlines()
if l.startswith('password: ')][0]
return re.match(r'password: "(.*)"', outtext).group(1)2)编辑行
.offlineimaprc
pythonfile = ~/offlineimap.py3)并更新远程部分
remotepasseval = get_keychain_pass(account="testUser@company.com", server="sub.domain.com")4)如果仍然存在问题,请尝试将offlineimap.py文件中的命令参数更改为
find-generic-password5)更正标签字符串,并在开始时只运行一次
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/offlineimap -u quiet</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>6)装载
launchctl load com.andypierz.offlineimap.plisthttps://stackoverflow.com/questions/36969958
复制相似问题