我正在尝试使用crontab每天发送一封电子邮件,但是现在通过尝试每分钟发送一次来进行测试。我正在使用python脚本scheduleCron.py计划cron作业以运行emailTest.py,但是它不起作用。当我分别运行时,它们效果很好! emailTest.py的目录正确,因为我使用其他非电子邮件代码进行了测试。但是设置cron作业后,我的邮件中出现EOFError,我不知道那是什么意思,因为这是我第一次尝试使用crontab或yagmail。我确实使用了yagmail的建议,即创建一个测试电子邮件帐户并启用第3方访问权限,该操作可以手动运行该脚本,因此不知道为什么现在会出现EOFError。
这是scheduleCron.py
from crontab import CronTab
my_cron = CronTab(user=True)
job = my_cron.new(command='/anaconda3/bin/python3 /Users/bgoldberg/PythonScripts/FunStuff/emailTest.py')
job.minute.every(1)
my_cron.write()
这是emailTest.py
import yagmail
import pandas as pd
from datetime import datetime
# create variables
df = pd.read_excel('/Users/bgoldberg/PythonScripts/FunStuff/holidays.xlsx')
df['DateCheck'] = df['Date'] == datetime.today().strftime('%m/%d')
df = df.loc[df['DateCheck'] == True]
df.reset_index(inplace=True)
if len(df) == 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
content = f'Happy {holiday1}! {link1}'
elif len(df) > 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
holiday2 = df.at[1, 'Holiday']
link2 = df.at[1, 'Link']
content = f'Happy {holiday1}! {link1} \nHappy {holiday2}! {link2}'
else:
pass
weekday = datetime.today().strftime('%A')
# create email
receiver = 'blah@gmail.com'
body = f'{content}'
yag = yagmail.SMTP('blah@gmail.com')
yag.send(
to = receiver,
subject = 'Fun Daily Holidays',
contents = body
)
这是我在邮件中收到的错误:
/anaconda3/lib/python3.7/getpass.py:91: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Password for <bggoldberg33@gmail.com>: Traceback (most recent call last):
File "/anaconda3/lib/python3.7/getpass.py", line 69, in unix_getpass
old = termios.tcgetattr(fd) # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/bgoldberg/PythonScripts/FunStuff/emailTest.py", line 39, in <module>
contents = body
File "/anaconda3/lib/python3.7/site-packages/yagmail/sender.py", line 147, in send
self.login()
File "/anaconda3/lib/python3.7/site-packages/yagmail/sender.py", line 246, in login
self._login(self.credentials)
File "/anaconda3/lib/python3.7/site-packages/yagmail/sender.py", line 203, in _login
password = self.handle_password(self.user, password)
File "/anaconda3/lib/python3.7/site-packages/yagmail/sender.py", line 209, in handle_password
return handle_password(user, password)
File "/anaconda3/lib/python3.7/site-packages/yagmail/password.py", line 20, in handle_password
password = getpass.getpass("Password for <{0}>: ".format(user))
File "/anaconda3/lib/python3.7/getpass.py", line 91, in unix_getpass
passwd = fallback_getpass(prompt, stream)
File "/anaconda3/lib/python3.7/getpass.py", line 126, in fallback_getpass
return _raw_input(prompt, stream)
File "/anaconda3/lib/python3.7/getpass.py", line 148, in _raw_input
raise EOFError
EOFError