如何解决邮件被发送,然后陷入尝试发送电子邮件的无限循环
邮件未发送,然后陷入尝试发送电子邮件的无限循环中。 cookie 函数在一个脚本中,而邮件函数在另一个脚本中。
def cookie(self):
self.driver.add_cookie({"name": "","value": ""})
cookie = self.driver.get_cookies()
print(cookie)
text_file = open(cookietxt,"w")
text_file.write("{0} -- {1}" .format(datetime.datetime.now(),cookie))
text_file.close()
time.sleep(fastlevel)
mail()
text_file = open(logtxt,"a")
text_file.write("{0} -- {1}" .format(datetime.datetime.now(),">Cookie was sent to your Email.< \n"))
text_file.close()
print("exit")
self.driver.close()
我正在尝试发送一封电子邮件,其中包含 cookie 和网站截图以及购物车中的文章。当我尝试仅使用 cookie 发送电子邮件时,它工作正常。图像与脚本位于同一文件夹中。
import smtplib,ssl,colorama,os
global cookietxt,receiver_email,sender_email
from colorama import Fore
from settings import *
from email.message import EmailMessage
def mail():
colorama.init(autoreset=True)
with open(cookietxt,"r") as file:
cookie = file.read()
newMessage = EmailMessage()
newMessage['Subject'] = "Crappy got something in cart"
newMessage['From'] = sender_email
newMessage['To'] = receiver_email
newMessage.set_content('RTX 3080 found on Alternate! \n\n' + cookie)
with open(screenshot,'rb') as f:
image_data = f.read()
image_type = imghdr.what(f.name)
image_name = f.name
newMessage.add_attachment(image_data,maintype='image',subtype=image_type,filename=image_name)
# Create a secure SSL context
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server,port) as smtp:
smtp.ehlo()
smtp.starttls(context=context)
smtp.ehlo()
smtp.login(sender_email,password)
smtp.send_message(newMessage)
print(Fore.BLUE + ">Email was sent!< \n")
smtp.quit()
print(Fore.BLUE + ">Connection to SMTP was successfully closed!< \n")
return x
if mail == "__main__":
x = mail()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。