通过公共电子邮件发送电子邮件很容易,而春天则更容易.接收收到的邮件怎么样?是否有易于使用的API,允许退回电子邮件,处理附件等.
我正在寻求各种电子邮件处理 - 例如.检查标题,如果它们符合某些条件(看起来像垃圾邮件),请删除连接,或检查收件人列表并执行特殊过滤.
看起来Python的smtpd库为处理收到的电子邮件提供了一个漂亮而简单的界面.
要在消息完全处理之前处理消息(例如,在标题看起来像垃圾邮件的情况下丢弃消息),我应该使用handle_connect吗?是否在某处记录了内部API(process_message除外)?示例代码在哪里?
还有,有人在生产中使用过smtpd吗?关于可靠性的任何想法等?
关于Twisted:我试图多次使用Twisted并且非常喜欢延迟模型,但是对于我目前的品味来说它有点过于复杂.我再看看,但是现在我对非Twisted实现更感兴趣.
我复制并粘贴了这个例子并填写了我自己的电子邮件地址.
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open('/Users/Jon/dev/iit/test-tools/logs/practice_tests.test_one.log', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()
me = 'Jon@MacBookPro.com'
you = 'jon.drowell@yahoo.com'
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用/etc/postfix/main.cf中的以下内容配置postfix以使用中继主机:
relayhost = [mailtrap.io]:2525
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
Run Code Online (Sandbox Code Playgroud)
通过telnet localhost 25后缀日志发送电子邮件后说:
Mar 20 10:49:52 hydra postfix/smtpd[19898]: connect from localhost[127.0.0.1]
Mar 20 10:49:52 hydra postfix/smtpd[19898]: improper command pipelining after MAIL from localhost[127.0.0.1]
Mar 20 10:49:52 hydra postfix/smtpd[19898]: 5F9BC2C30A1: client=localhost[127.0.0.1]
Mar 20 10:49:52 hydra postfix/cleanup[19902]: 5F9BC2C30A1: message-id=<20120320084952.5F9BC2C30A1@hydra>
Mar 20 10:49:52 hydra postfix/qmgr[19890]: 5F9BC2C30A1: from=<a@b.com>, size=290, nrcpt=1 (queue active)
Mar 20 10:49:52 hydra postfix/smtp[19904]: warning: SASL authentication failure: No worthy mechs found
Mar 20 10:49:52 hydra …Run Code Online (Sandbox Code Playgroud) 我在python中使用smtpd模块创建了一个SMTP服务器.我已经能够收到电子邮件并将它们存储在sqlite数据库中,但问题是我不知道如何检索它们.
我尝试使用以下代码,但我不确定它是否可靠.
import smtpd
import asyncore
import sqlite3
import datetime
import dol # custom module that i have created to do authentication while retrieving the email
import threading
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
print 'Receiving message from:', peer
print 'Message addressed from:', mailfrom
print 'Message addressed to :', rcpttos
print 'Message length :', len(data)
print "Message :",data
print data.split("\n\n")
smtp_auth_cursor.execute("SELECT username FROM smtp_auth_table")
smtp_entry=smtp_auth_cursor.fetchall()
print smtp_entry
subject="project"
for x in smtp_entry:
x=x[0]
name=x+"@example.com"
if x in name: …Run Code Online (Sandbox Code Playgroud) 我以这种方式启动服务器(在mac上):
python -m smtpd -n -c DebuggingServer localhost:9999
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误或任何其他通知.我想这意味着一切都好,如果我错了,请纠正我.
但是当我从django shell或我的应用程序发送电子邮件时,使用带有fail_silently = False的send_mail/mail_managers,我在smtpd调试服务器上看不到任何输出.我没有得到任何SMTP错误,send_mail/mail_managers返回1.
我跑了:
lsof -i | grep LISTEN
Run Code Online (Sandbox Code Playgroud)
看看是否有人收听9999端口,而且没有人收听.这是否意味着smtp调试服务器出了问题?它应该显示在听众列表中吗?
我的电邮设置:
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 9999
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python发送电子邮件并使用以下代码:
import smtplib
import datetime
SERVER = "localhost"
PORT = 1025
FROM = "me@mydevice.com"
TO = ["myemailaddress@something.com"]
SUBJECT = "test"
dt = datetime.datetime.now()
TEXT = "blabla bla @ " + str(dt)
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ",".join(TO), SUBJECT, TEXT)
server = smtplib.SMTP(SERVER,PORT)
server.sendmail(FROM,TO,message)
server.quit()
Run Code Online (Sandbox Code Playgroud)
没有安装/设置任何STMP服务器,我只是使用这个:
python -m smtpd -n -c DebuggingServer localhost:1025
Run Code Online (Sandbox Code Playgroud)
代码似乎运行正常,没有错误,服务器甚至通知我:
---------- MESSAGE FOLLOWS ----------
From: me@mydevice.com
To: myemailaddress@something.com
Subject: test
X-Peer: 127.0.0.1
blabla bla @ 2014-01-29 14:44:37.219724
------------ END …Run Code Online (Sandbox Code Playgroud)