使用 smtp 发送电子邮件(需要帮助)

时间:2021-04-14 05:45:09

标签: python smtp discord.py

async def test(ctx, arg1, arg2):
    _smpt = smtplib.SMTP('mail.cock.li', 587)
    _smpt.starttls()
    username = ('my email@cock.li')
    password = ('my pass')
    try:
        _smpt.login(username, password)
    except:
        await ctx.send(f"incorrect password or email")
    reciever = (f'{arg1}')
    message = (f'{arg2}')
    _smpt.sendmail(username, reciever, message)

有谁知道为什么我使用 https://cock.li/server 和 discord.py bot 命令给我一个错误

错误是SMTPResponseException: (454, b'4.7.0 TLS not available due to local problem')

1 个答案:

答案 0 :(得分:0)

注意:更改发件人邮件 ID 的安全设置,使其允许访问低安全性应用程序(可以在邮件设置中手动完成)

使用以下代码

import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
sender_email_id=input("sender mail")
sender_email_id_password=input("sender mail password")
s.login(sender_email_id, sender_email_id_password)
message = "Message_you_need_to_send"
receiver_email_id=input("receiver mail")
s.sendmail(sender_email_id, receiver_email_id, message)
s.quit()