괜찮 았던 사람들, 나는 인터넷을 오래 동안 보았으며 이에 대한 대답을 찾을 수 없었습니다. 나는 많은 제안을 시도했지만 그것이 작동하도록 할 수 없습니다. 파이썬 (smtplib과 이메일 모듈)과 gmail 서비스를 사용하여 이메일을 보내려고합니다. 여기 내 수입 패키지는 : 여기Python 전자 메일 보내기 TypeError : 예상되는 문자열 또는 버퍼
import time, math, urllib2, urllib, os, shutil, zipfile, smtplib, sys
from email.mime.text import MIMEText
하고있는 이메일을 보내는 내 데프 문 :
def sendmessage():
print('== You are now sending an email to Hoxie. Please write your username below. ==')
mcusername = str(raw_input('>> Username: '))
print('>> Now your message.')
message = str(raw_input('>> Message: '))
print('>> Attempting connection to email host...')
fromaddr = '[email protected]'
toaddrs = '[email protected]'
username = '[email protected]'
password = '1013513403'
server = smtplib.SMTP('smtp.gmail.com:587')
subject = 'Email from',mcusername
content = message
msg = MIMEText(content)
msg['From'] = fromaddr
msg['To'] = toaddrs
msg['Subject'] = subject
try:
server.ehlo()
server.starttls()
server.ehlo()
except:
print('!! Could not connect to email host! Check internet connection! !!')
os.system('pause')
main()
else:
print('>> Connected to email host! Attempting secure login via SMTP...')
try:
server.login(username,password)
except:
print('!! Could not secure connection! Stopping! !!')
os.system('pause')
main()
else:
print('>> Login succeeded! Attempting to send message...')
try:
server.sendmail(fromaddr, toaddrs, msg)
except TypeError as e:
print e
print('Error!:', sys.exc_info()[0])
print('!! Could not send message! Check internet connection! !!')
os.system('pause')
main()
else:
server.quit()
print('>> Message successfully sent! I will respond as soon as possible!')
os.system('pause')
main()
내가 광범위하게 내가 감히 디버깅이 얻을 수있다 :
>> Login succeeded! Attempting to send message...
TypeError: expected string or buffer
을 즉, 로그인에 성공했지만 메시지를 보내려고하면 중단되었습니다. 나를 괴롭히는 한 가지는 어디를 가리 키지 않는다는 것입니다. 또한 제 작성법이 그다지 좋지 않으므로 사이버 왕따는 없습니다.
도움이 될 것입니다. 감사. 두 개의 값을 전달하기 때문에
subject = 'Email from',mcusername
당신이 문자열로 제목을 만들 것으로 예상하는 경우, 그 사실 튜플로 만들어지고 :