Skip to content Skip to sidebar Skip to footer

Payload Of An Email In String Format, Python

I got payload as a string instance using get_payload() method. But I want my payload in a way where I could access it word by word I tried several things like as_string() method, f

Solution 1:

Just tested your snippet with a couple of my own raw emails. Works fine...

get_payload() returns either a list or string, so you need to check that first

ifisinstance(payload, list):
    for m in payload:
        printstr(m).split()

else:
    printstr(m).split()

Edit

Per our discussion, your issue was that you were not checking is_multipart() on the fp object, which actually is a message instance. If fp.is_multipart() == True, then get_payload() will return a list of message instances. In your case, based on your example mail message, it was NOT multipart, and fp was actually the object you were interesting in.

Solution 2:

I got my payload as a string as my fp was not multipart If it could have been a multipart, it would have returned a list of strings so now I can just use the following code

payload=fp.get_payload()
abc=payload.split(" ")

it gives me the output as follows ['good', 'day\nhttp://72.167.116.186/image/bdfedx.php?iqunin=3D41\n\n', '', '', '', '', '', '', '', '', '', '', '', 'Sun,', '18', 'Dec', '2011', '10:53:43\n_________________\n"She', 'wiped', 'him', 'dry', 'with', 'soft', 'flannel,', 'and', 'gave', 'him', 'some', 'clean,', 'dry', 'clothes,=\n', 'and', 'made', 'him', 'very', 'comfortable', 'again."', '(c)', 'Lyrica', 'wa946758\n']

thanks to jdi :) p.s. couldnt post it as an answer yesterday, as there was some restriction with points

Post a Comment for "Payload Of An Email In String Format, Python"