Pekala çocuklar, internete çağlar boyunca baktım ve buna bir cevap bulamadım. Birçok öneride bulundum ama işe yaramayacak gibi görünmüyorum. Python (smtplib ve e-posta modülleri) ve gmail servisini kullanarak bir e-posta göndermeye çalışıyorum. İşte benim ithal paketler şunlardır: BuradaPython e-posta gönderme TypeError: Beklenen dize veya arabellek
import time, math, urllib2, urllib, os, shutil, zipfile, smtplib, sys
from email.mime.text import MIMEText
ve e-posta göndermek için benim def deyimi:
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()
Ben yoğun Cüret olarak debug ve bu olsun adres:
>> Login succeeded! Attempting to send message...
TypeError: expected string or buffer
Bu, giriş yapmayı başardığı anlamına gelir, ancak mesajı göndermeye çalışırken durdu. Beni boggles bir şey, o nereye işaret etmiyor olmasıdır. Ayrıca benim kodum o kadar da iyi olmayabilir ki siber zorbalık yok.
Herhangi bir yardım çok takdir edilecektir! Teşekkürler. Eğer iki değer geçiyoruz çünkü
subject = 'Email from',mcusername
bir dize olarak konuyu oluşturmak için bekliyoruz, onun aslında bir başlığın içine yapılmaktadır: