I've created that bot and I want to make it send invitation for my association's discord channel towards the members that want to join for a limited number of people. There is my code and I hope you can help me figure out why it can't send the email. There is the error I get:
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