Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 无法准确估计我通过smtplib发送的电子邮件数量_Python 3.x_While Loop_Smtplib - Fatal编程技术网

Python 3.x 无法准确估计我通过smtplib发送的电子邮件数量

Python 3.x 无法准确估计我通过smtplib发送的电子邮件数量,python-3.x,while-loop,smtplib,Python 3.x,While Loop,Smtplib,我正在编写一个代码,使用smtplib通过Python发送电子邮件,并试图制作一个计数器,在执行键盘中断之前查看我发送了多少邮件 这是密码 import smtplib, ssl port = 465 smtp_server = "smtp.gmail.com" sender_email = "generic@gmail.com" password = input("Type your password and press enter: &q

我正在编写一个代码,使用smtplib通过Python发送电子邮件,并试图制作一个计数器,在执行键盘中断之前查看我发送了多少邮件

这是密码

import smtplib, ssl

port = 465
smtp_server = "smtp.gmail.com"
sender_email = "generic@gmail.com"

password = input("Type your password and press enter: ")

receiver_email = str(input("Enter Receiver's Email: :"))

subject = str(input("Enter Subject: : "))
m = str(input("Enter Message: :"))

message = """\
Subject: {sub}

{msg}.""".format(sub = subject, msg = m)

context = ssl.create_default_context()
t = 1
x = 0

server = smtplib.SMTP_SSL(smtp_server, port, context=context)
server.login(sender_email, password)

while t == 1:
    try:
        
        server.sendmail(sender_email,receiver_email,message)
        x += 1

    except KeyboardInterrupt:
        t = 0
print("Message Successfully Sent", x, "time(s).")

现在,当我运行代码时,有时会得到一个大于预期的数字,有时会得到正确的数字,有时会得到一个小于预期的数字。我该如何解决这个问题