首页 > 解决方案 > 如何发送一封电子邮件,其中包含由 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

标签: pythonpython-3.xdiscord.py

解决方案


就错误而言,localhost(您的计算机)不接受使用 SMTP 的请求。港口很可能已经关闭。

打开端口 (Linux)
打开端口 (Windows)


推荐阅读