how can i stop smtplib from send with a command in discord py ?
Hello beautiful people , so i am coding a discord bot that can send emails on given smtp server and letter,maillist but lets say i have a list of 20 emails and i started sending , and i realized the email has something , a mistake , and i want to stop the process from w command without quiting the bot entirely
and i know that is server.quit()
i tried to put it in every single place even created a new command for it and i still cannot figure it out :3
This is my code over here! :
@bot.command()
async def smtp(ctx, stat=None):
smtp_server = await eee(ctx, f"{ctx.author.mention} Smtp server ?", timeout=60.0)
port = await eee(ctx, f"{ctx.author.mention} Smtp port ?", timeout=60.0)
user = await eee(ctx, f"{ctx.author.mention} Smtp user ?", timeout=60.0)
password = await eee(ctx, f"{ctx.author.mention} Smtp password ?", timeout=60.0)
def generate_messages(recipients):
with open(letter_path, 'r') as myfile:
data = myfile.read()
for recipient in recipients:
message = EmailMessage()
message['Subject'] = letter_subject
message['From'] = Address(letter_From, *user.split("@"))
message['To'] = recipient
message.set_content(data, 'html')
yield message
messages = generate_messages(mails)
if port == '587':
with smtplib.SMTP(smtp_server, port) as server:
try:
server.login(user, password)
embed = discord.Embed(title=f"SMTP CONNECTION DONE",
description=f"", color=3447003)
for message in messages:
now = datetime.now()
server.send_message(message)
time.sleep(10)
embed.add_field(name=" [+] ",
value=f" {message['To']} SENT {time.strftime('%X')}", inline=False)
await ctx.send(embed=embed)
except smtplib.SMTPException:
await ctx.send('DMTP DEAD')
elif port == '465':
with smtplib.SMTP_SSL(smtp_server, port) as server:
try:
server.login(user, password)
embed = discord.Embed(title=f"SMTP CONNECTION DONE",
description=f"", color=3447003)
await ctx.send(embed=embed)
for message in messages:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
server.send_message(message)
time.sleep(10)
embed2 = discord.Embed(title=" [+] SENT! [+] ", description=f" {message['To']} SENT {time.strftime('%X')}"
, color=3447003)
await ctx.send(embed=embed2)
except smtplib.SMTPException or stat == 'stop':
await ctx.send('SMTP DEAD OR stopped')
elif port == '465' or '587':
await ctx.send('PORT NOT SUPPORTED')
quit()