gpt4 book ai didi

python - 套接字错误 - 使用 gmail 发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:29 25 4
gpt4 key购买 nike

我正在使用来自 this 的代码使用 gmail 发送电子邮件的文章。

代码如下

import smtplib

def sendemail(from_addr, to_addr_list, cc_addr_list,
subject, message,
login, password,
smtpserver='smtp.gmail.com:587'):
header = 'From: %s\n' % from_addr
header += 'To: %s\n' % ','.join(to_addr_list)
header += 'Cc: %s\n' % ','.join(cc_addr_list)
header += 'Subject: %s\n\n' % subject
message = header + message

server = smtplib.SMTP(smtpserver)
server.starttls()
server.login(login,password)
problems = server.sendmail(from_addr, to_addr_list, message)
server.quit()
return problems

当我运行它时,我收到以下套接字错误。

socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions

编辑:回溯

O:\Send Email With Attachment>SendEmail_Ver2.py
Traceback (most recent call last):
File "O:\Send Email With Attachment\SendEmail_Ver2.py", line 26, in <module>
password = 'XXXXXXXXXXX')
File "O:\SendEmail_Ver2.py", line 13, in sendemail
server = smtplib.SMTP(smtpserver)
File "C:\Program Files (x86)\Python26\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\Program Files (x86)\Python26\lib\smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Program Files (x86)\Python26\lib\smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Program Files (x86)\Python26\lib\socket.py", line 561, in create_connection
raise error, msg socket.error: [Errno 10013] An attempt was made to access a socket in
a way forbidden by its access permissions`

我如何获得脚本使用端口 587 的权限?还是 gmail 可以使用更高的端口号?

谢谢

最佳答案

问题出在 McAfee Antivirus。它阻塞了套接字连接。

来自 McAfee 访问保护日志

23/08/2013 10:23:54 a.m. Blocked by port blocking rule C:\Program Files (x86)\Python26\python.exe Anti-virus Standard Protection:Prevent mass mailing worms from sending mail 74.125.25.108:25

我完全禁用了 McAfee,之后它运行良好。

关于python - 套接字错误 - 使用 gmail 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18370235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com