Reputation:
I'm new to Python, so I'm having trouble figuring out how to get at a specific element in a Mail object. I'm creating the Mail object in a function and returning it:
data = getMessage()
When I do print (data)
it gives me the following:
{
'from': {
'email': '[email protected]'
},
'subject': 'My Subject Line',
'personalizations': [{
'to': [{
'email': '[email protected]'
}]
}],
'content': [{
'type': 'text/plain',
'value': 'http://localhost/some-url?t=ab99ceccf4ab4f97b1d014bb5e89707c'
}]
}
Now, I can do something like print (data.subject)
and it gives me My Subject Line
, but I can't figure out how to get to the value
property of content
. I just want to print the URL to the console for testing so I don't have to wait for the email to come through.
Now I'm just printing it from inside the function itself because that's the easy way, but I'd still like to know how to get it from the Mail object.
Upvotes: 1
Views: 348
Reputation: 149
The content thingy is a list with only 1 entry.
You can reach it by doing:
data["content"][0]["value"]
or if you aren't sure if there is only 1 entry:
for content in data["content"]:
content["value"]
Upvotes: 1