我编写了一段python代码,用于使用SMTP发送电子邮件。
我用过smtplib。它工作正常。
我想模拟许多用户发送电子邮件的场景。因此,为避免服务器过载,我希望该消息不应存储在邮件服务器上。相反,它们应存储在本地目录中。但邮件服务器应该被击中。
如何在python中执行此操作。这就是我写的
SMTP_SERVER = 'mailserver.com'
now = datetime.now()
SMTP_PORT = 25
sender = "test1@test.com"
recipient = "test2@test.com"
subject = "Test Subject"
Body = "This is a test messages"
day = now.strftime('%a')
date = now.strftime('%d %b %Y %X')
Headers = ["From: "+sender, "Subject: "+subject, "To:"+recipient,"MIME-Version: 1.0", "Content-Type: text/html", "Date: "+day+','+date]
Headers = "\r\n".join(Headers)
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
session.ehlo()
session.starttls()
session.ehlo()
session.sendmail(sender,recipient, Headers +"\r\n\r\n" + Body)