Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 530错误-Google SMTP服务器需要身份验证_Python_Sockets_Smtp_Gmail_Certificate - Fatal编程技术网

Python 530错误-Google SMTP服务器需要身份验证

Python 530错误-Google SMTP服务器需要身份验证,python,sockets,smtp,gmail,certificate,Python,Sockets,Smtp,Gmail,Certificate,我无法使Mail-to:SMTP命令在此python套接字程序中工作。我总是 530-5.5.1 Authentication Required …如您所见,我没有提供ca_certs和cert_reqs参数。我似乎找不到任何在Windows for Python中使用证书编程的好例子 from socket import * import ssl, pprint msg = "\r\n I love computer networks!" endmsg = "\r\n.\r\n" # C

我无法使Mail-to:SMTP命令在此python套接字程序中工作。我总是

530-5.5.1 Authentication Required
…如您所见,我没有提供ca_certs和cert_reqs参数。我似乎找不到任何在Windows for Python中使用证书编程的好例子

from socket import *
import ssl, pprint

msg = "\r\n I love computer networks!"
endmsg = "\r\n.\r\n"

# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = "smtp.gmail.com"
port = 465

# Create socket called clientSocket and establish a TCP connection with mailserver
clientSocket = socket(AF_INET, SOCK_STREAM)
ssl_clientSocket = ssl.wrap_socket(clientSocket)
                                   #ca_certs="C:\Users\wgimson\Downloads\root",
                                   #cert_reqs=ssl.CERT_REQUIRED)
ssl_clientSocket.connect((mailserver, port))

# DEBUG
print repr(ssl_clientSocket.getpeername())
print ssl_clientSocket.cipher()
print pprint.pformat(ssl_clientSocket.getpeercert())
# DEBUG


recv = ssl_clientSocket.read(1024)
print
print recv


# If the first three numbers of what we receive from the SMTP server are not
# '220', we have a problem
if recv[:3] != '220':
    print '220 reply not received from server.'
else:
    print "220 is good"

# Send HELO command and print server response.
heloCommand = 'HELO Alice\r\n'
ssl_clientSocket.write(heloCommand)
recv1 = ssl_clientSocket.recv(1024)
print recv1


# If the first three numbers of the response from the server are not
# '250', we have a problem
if recv1[:3] != '250':
    print '250 reply not received from server.'
else:
    print "250 is good"


# Send MAIL FROM command and print server response.
mailFromCommand = 'MAIL From: wgimson@gmail.com\r\n'
ssl_clientSocket.send(mailFromCommand)
recv2 = ssl_clientSocket.recv(1024)
print recv2

# If the first three numbers of the response from the server are not
# '250', we have a problem
if recv2[:3] != '250':
    print '250 reply not received from server.'
else:
    print "250 means still good"

这适用于谷歌邮件

def send_mail(recipient, subject, message, contenttype='plain'):
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_HOST_USER = 'some_account@gmail.com'
    EMAIL_HOST_PASSWORD = 'some_password'

    mime_msg = email.mime.text.MIMEText(message, contenttype, _charset="UTF-8")
    mime_msg['Subject'] = subject
    mime_msg['From'] = EMAIL_HOST_USER
    mime_msg['To'] = recipient

    smtpserver = smtplib.SMTP(EMAIL_HOST, EMAIL_PORT)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)   
    smtpserver.sendmail(EMAIL_HOST_USER, recipient, mime_msg.as_string())
    smtpserver.close()

是的,但不幸的是我不能使用smtplib模块,这是学校的作业。