简体   繁体   English

收到的电子邮件中的抄送收件人是Python列表吗? (Google App Engine)

[英]Is the cc recipients in a received email a Python list? (Google App Engine)

I am trying to pull the cc'ed email addresses from received email. 我正在尝试从收到的电子邮件中提取抄送的电子邮件地址。 I am working in the development server. 我正在开发服务器中工作。

The tutorial says that "cc contains a list of the cc recipients." 该教程说“抄送包含抄送收件人的列表”。 But it seems that message.cc returns a string. 但是似乎message.cc返回一个字符串。 I am just using the code I copied from the cookbook: 我只是使用从食谱复制的代码:

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) 

So if I have 1 cc, the log shows: 因此,如果我有1 cc,则日志显示:

CC email is cc12@example.com

If there are more than 1: 如果超过1:

CC email is cc12@example.com, cc13@example.com

To get the first email "cc12@example.com", I tried: 为了获得第一封电子邮件“ cc12@example.com”,我尝试:

logging.info("CC email is %s" % message.cc[0])

but this gives: 但这给出了:

CC email is c

so the result is treated as a string. 因此将结果视为字符串。

When I try 当我尝试

logging.info("CC email is %s" % list(message.cc) logging.info(“抄送电子邮件是%s”%列表(message.cc)

I get 我懂了

['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'

Again, it appears that message.cc returns string not list. 同样, message.cc似乎返回的字符串不是list。

Do I need to use regex to get the emails? 我需要使用正则表达式来获取电子邮件吗? Any suggestions about what I am doing wrong? 关于我在做什么错的任何建议吗? Thanks! 谢谢!

尝试:

cc_list = message.cc.split(',')

cc 抄送

A recipient's email address (a string) or a list of email addresses to appear on the Cc: line in the message header. 收件人的电子邮件地址(字符串)或要显示在邮件标题中“抄送:”行上的电子邮件地址列表。

Message Fields 讯息栏位

cc is a string cc是一个字符串

message.cc.split(", ")[0] is "cc12@example.com" that you want. message.cc.split(“,”)[0]是您想要的“ cc12@example.com”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM