0
我對編程很陌生,所以我來這裏尋求幫助。我正在嘗試製作一個簡單的郵件羣發器,目前不會使用它,但在將來的某個時候,我可能會在我的IT工作中使用它。我的代碼似乎不想爲我工作。用python編寫電子郵件
import sys
import smtplib
emailfile = raw_input('Please enter the name of the text file that includes all email addresses: ')
emailtosendfrom = raw_input('Enter your email address to send from: ')
msgfile = raw_input('Please enter the text file name that includes the message you want to send out :')
email = open(emailfile, 'r')
toaddrs = email
msg = open(msgfile, 'r')
# Credentials
password = raw_input('Please enter your email password : ')
# Send mail
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(emailtosendfrom,password)
with open(emailfile) as f:
emailsort = f.readlines()
for user in emailsort:
server.sendmail(emailtosendfrom, user, msg)
f.close()
server.quit()
此代碼返回錯誤:
Traceback (most recent call last):
File "mail.py", line 26, in <module>
server.sendmail(emailtosendfrom, line, msg)
File "C:\Python27\lib\smtplib.py", line 717,
esmtp_opts.append("size=%d" % len(msg))
TypeError: object of type 'file' has no len()
任何幫助,將不勝感激。謝謝!