我试图从收到的电子邮件中提取抄送的电子邮件地址。我在开发服务器工作。在
The tutorial表示“抄送包含抄送收件人的列表”。但是message.cc
似乎返回了一个字符串。我只是用我从食谱上抄下来的代码:
class ReceiveEmail(InboundMailHandler):
def receive(self, message):
logging.info("Received email from %s" % message.sender)
plaintext = message.bodies(content_type='text/plain')
for text in plaintext:
txtmsg = ""
txtmsg = text[1].decode()
logging.info("Body is %s" % txtmsg)
logging.info("CC email is %s" % message.cc)
如果我有1毫升,日志显示:
CC email is cc12@example.com
如果有1个以上:
CC email is cc12@example.com, cc13@example.com
收到第一封邮件”cc12@example.com“,我试着:
^{pr2}$但这会带来:
CC email is c
所以结果被视为一个字符串。在
当我尝试的时候
在日志记录.info(“抄送电子邮件为%s”%列表(邮件.cc)在
我明白了
['c', 'c', '1', '2', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ',', ' ', 'c', 'c', '1', '3', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ',', ' ', 'c', 'c', '1', '4', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm'
同样,message.cc
返回string not list。在
我需要使用正则表达式来获取电子邮件吗?有什么关于我做错什么的建议吗?谢谢!在
cc
收件人的电子邮件地址(字符串)或邮件标题中Cc:line上显示的电子邮件地址列表。
Message Fields
cc是字符串
message.cc.split(“,”[0]为“cc12@example.com“你想要的。
尝试:
相关问题 更多 >
编程相关推荐