python - 如何发送一封电子邮件,其中包含由 python 中的不和谐机器人创建的邀请,以获得最大使用量?
问题描述
我已经创建了那个机器人,我想让它向想要加入的成员发送我协会的不和谐频道的邀请,但人数有限。有我的代码,我希望你能帮我弄清楚为什么它不能发送电子邮件。我得到的错误是:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The above exception was the direct cause of the following exception:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
import discord
import random
import smtplib
from email.message import EmailMessage
from discord.ext import commands
bot = commands.Bot(command_prefix = '-')
welcome_channel_id = 783308696192811048
@bot.command()
async def inv(ctx, a:int, email:str):
msg = EmailMessage()
invlink = await ctx.channel.create_invite(max_age= 300,max_uses = a, temporary = False)
msg.set_content(f'Hello,\nHere are the invites for the fake discord server{invlink} for a total of {a} uses\n Have a great day,\n faker!')
msg['Subject'] = 'Invites for discord'
msg['From'] = 'fake@email.com'
msg['To'] = email
s=smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
return
解决方案
就错误而言,localhost
(您的计算机)不接受使用 SMTP 的请求。港口很可能已经关闭。
推荐阅读
- c# - Unity C# 编码类型
- python - 使用管道时 open() 与 os.open() 的行为
- angularjs - 使用 Azure AD SSO 时出现 CORS 问题
- c# - 如何压缩 4 个或更多数组
- django - Django 翻译:评估一个字符串是否是任何可用语言的翻译
- python-3.x - if not img==None: ValueError: 具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
- rust - 我可以从 Clap 的 arg 解析器中获得静态生命周期吗?
- scala - 在 WindowedStream 中查找 Top K 元素 - Flink
- c# - 从 Debug 切换到 Release 配置时未解决的引用
- python - Fuseki 服务器在哪里存储三重数据?