简体   繁体   中英

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. 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:

CC email is cc12@example.com

If there are more than 1:

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

To get the first email "cc12@example.com", I tried:

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)

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.

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

message.cc.split(", ")[0] is "cc12@example.com" that you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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