[英]python - read email from postfix in python on linux
I'm very new to postfix and python. 我对postfix和python很陌生。 I've setup postfix on Ubuntu and have configured the
main.cf
with mailbox_command = /home/someuser/test.py
我已经在Ubuntu上安装Postfix和配置了
main.cf
与mailbox_command = /home/someuser/test.py
test.py: test.py:
#!/usr/bin/python
import sys, MySQLdb
email_input = sys.stdin
db = MySQLdb.connect(host="localhost",
user="user",
passwd="password",
db="test")
cur = db.cursor()
sql = "insert into postfix (value) values (%s)"
cur.execute(sql, (email_input,))
db.commit()
db.close()
I was expecting the content of the email to be inserted into the field but instead I ended up with <open file '<stdin>', mode 'r' at 0x7f018b3b40c0>
我原本希望将电子邮件的内容插入到字段中,但是最终我得到了
<open file '<stdin>', mode 'r' at 0x7f018b3b40c0>
How do I get the raw email string from what seems to be that memory address? 如何从该内存地址中获取原始电子邮件字符串?
sys.stdin
is an object of type TextIOWrapper
and cur.execute
is expecting a string. sys.stdin
是类型的对象TextIOWrapper
和cur.execute
期待一个字符串。 You need to instruct sys.stdin
to read input and return the string representing it. 您需要指示
sys.stdin
读取输入并返回代表它的字符串。 Use either readline
or readlines
depending on what you're trying to do. 使用
readline
或readlines
取决于您要执行的操作。
cur.execute(sql, (sys.stdin.readlines(),))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.