想通过自己的刚买了给别的邮箱发邮件
使用的是stmp
代码如下
Python code
# -*-encoding:utf-8 -*-
#newemail.py
import smtplib
from email.MIMEText import MIMEText
def prompt(prompt):
return raw_input(prompt).strip()
#POP3host=prompt('POP3host:')
toaddr=prompt('TO:')
username=prompt('Username:')
passw=prompt('Password:')
fromaddr=username+'@gmail.-com'
msgtext='FROM:%s,TO:%s\n\n'%(fromaddr,toaddr)
while 1:
try:
line = raw_input()
except EOFError:
break
if not line:
break
msgtext = msgtext + line
print "Message length is " + repr(len(msgtext))
msg=MIMEText(msgtext,"plain")
msg['Subject']="test subject"
server=smtplib.SMTP('stmp.gmail.com')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username,passw)
server.sendmail(fromaddr,toaddr,msg.as_string())
server.quit()
运行脚本
输入信息后
得到这么多错误
Traceback (most recent call last):
File "d:\pythonwork\newemail.py", line 26, in <module>
server=smtplib.SMTP('stmp.gmail.com')
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
调到凌晨1:50啊有木有!!!
不知道,粘贴上去的代码会不会被吃掉缩进啊有木有!!!
server=smtplib.SMTP('stmp.gmail.-com:587')
错别字了吧,所以解析地址失败...