【问题标题】:python - read email from postfix in python on linuxpython - 从 Linux 上的 python 中的 postfix 读取电子邮件
【发布时间】:2017-02-25 18:24:16
【问题描述】:

我对 postfix 和 python 很陌生。我已经在 Ubuntu 上设置了 postfix,并用 mailbox_command = /home/someuser/test.py 配置了 main.cf

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()

我希望将电子邮件的内容插入到字段中,但结果却是<open file '<stdin>', mode 'r' at 0x7f018b3b40c0>

如何从似乎是该内存地址的地方获取原始电子邮件字符串?

【问题讨论】:

    标签: python linux postfix


    【解决方案1】:

    sys.stdin 是 TextIOWrapper 类型的对象,cur.execute 需要一个字符串。您需要指示sys.stdin 读取输入并返回代表它的字符串。使用readline 或readlines,具体取决于您要执行的操作。

    cur.execute(sql, (sys.stdin.readlines(),))
    

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 2019-09-02
      • 2016-12-27
      • 2020-07-24
      • 2010-10-05
      • 1970-01-01
      • 2013-09-13
      • 2011-07-01
      • 2021-06-22
      相关资源
      最近更新 更多