#!/usr/bin/python
import socket
import smtplib
gmail_user = 'username'
gmail_pwd = 'xxxxxx'
FROM = 'my@gmail.com'
TO = ['reciver1@gmail.com','reciver2@gmail.com']
a ="55"
SUBJECT = "this is my testing man"
TEXT = "Testing sending mail using gmail servers"+a+"care full"
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP('smtp.gmail.com',587) #or port 465 doesn't seem to work!,587,'72.167.1.187'
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
#server.quit()
server.close()
print 'successfully sent the mail'
except Exception, error:
print "Unable to send e-mail: '%s'." % str(error)
我成功从本地系统发送邮件,
我在远程服务器上运行相同的代码我得到了这个错误
Unable to send e-mail: '(97, 'Address family not supported by protocol')'.
为什么这段代码在远程服务器上不起作用,请帮帮我
答案 0 :(得分:0)
答案 1 :(得分:0)
显然,您需要进入您的Gmail帐户才能将其发送给收件人,为此,您需要更改您的g-mail设置以接受来自安全性较低的应用程序(SMTP)的登录,这应该会修复您的问题