gpt4 book ai didi

python - 我如何在 python 中发送电子邮件?

转载 作者:行者123 更新时间:2023-11-28 23:03:23 26 4
gpt4 key购买 nike

我在网上看过,但每次我尝试连接到本地主机时,它都说连接被拒绝。我需要登录有效的电子邮件地址才能发送电子邮件吗?这是我的确切代码。

>>> import smtplib

>>> sender = 'from@fromdomain.com'

#this is my exact sender name bc i don't know if i need to use a valid email address or if i can just make up one since i dont need a password and username

>>> receiver = ['to@todomain.com']

#again, i dont know what to use for the receiver email address

>>> message = 'this is a test'

>>> s = smtplib.SMTP('localhost')

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
s = smtplib.SMTP('localhost')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 61] Connection refused

连接被拒绝错误是我的问题。我在网上看过,但我不知道如何连接它。

最佳答案

如果您想使用 gmail 发送您的消息,可以使用一些代码:http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/你可以使用。它应该很容易解释..

关于python - 我如何在 python 中发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8552826/

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