通过python从localhost发送电子邮件到localhost [英] send email to localhost from localhost via python
问题描述
import smtplib
from email.mime.text import MIMEText
fp = open('textfile','rb')
msg = MIMEText(fp.read())
fp.close()
me = me_email @ localhost'
你='me_again_email @ localhost'
msg ['Subject'] ='%s'的内容%fp
msg ['From'] =我
msg ['To'] =你
s = smtplib.SMTP('localhost')
s.sendmail(我,[你],msg.as_string())
s.quit()
我没有配置sendmail,因此它会抛出错误。但是,由于我只想测试我的Web服务,我不担心sendmail现在不能发送电子邮件。我的服务旨在从数据库中提取一些记录,并向他们发送电子邮件。所以我想知道如果这个连接,python从db输入和推送电子邮件正在工作。我想收到通过脚本发送的本地主机上的电子邮件。
An SMTP服务器。除非您配置SMTP服务器,否则无法发送电子邮件。有关使用python smtplib
的更多信息,请参见 pymotw.com , tutorialspoint.com 和 Python文档。
I'm building and testing a web service on my local machine before i put it in production. I want to test the mail service. I'm using the standard python email and smtplib libraries.
import smtplib
from email.mime.text import MIMEText
fp = open('textfile', 'rb')
msg = MIMEText(fp.read())
fp.close()
me = 'me_email@localhost'
you = 'me_again_email@localhost'
msg['Subject'] = 'The contents of %s' %fp
msg['From'] = me
msg['To'] = you
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
I have not configured sendmail and hence it throws an error. But since I just want to test my web service I am not concerned if sendmail cant send an email right now. My service is designed to pulls some records off db and send them an email. So i want to know if this connection, python taking inputs from db and pushing an email is working. I want to receive the email on localhost sent via the script.
An SMTP server needs to be configured for sending emails. Sending emails is not possible unless you configure an SMTP server. More information on using python smtplib
can be found in pymotw.com, tutorialspoint.com and Python docs.
这篇关于通过python从localhost发送电子邮件到localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!