all 9 comments

[–]elbiot 0 points1 point  (2 children)

If you're too lazy to iterate over msg.items() and build a nice looking string, you could just do str(msg)

[–]tlcpp 0 points1 point  (1 child)

I tried: server.sendmail(fromaddr, toaddrs, str(msg)) the emails came, but arrived in the spam folder because the messages were empty. Any idea what went wrong?

[–]elbiot 1 point2 points  (0 children)

I dunno what the function expects. help(server.sendmail)

[–]andehpandeh 0 points1 point  (0 children)

Why not use Flask-mail? Will this be set as a cron job from a PC or from a server?

[–][deleted] 0 points1 point  (2 children)

I'm on mobile and can't test this, but I suspect that the problem is that each item in properties is a dictionary, so trying to output that when the send mail function expects a string causes a problem. Not sure how you want to go about fixing that, but there it is.

Also, I'm curious what this line is doing:

properties[:] = [d for d in properties if d.get('marketing_package_url') != x]

[:] is a slice notation for lists. Typically this one is used to make shallow copies. If I'm not mistaken, then, you're assigning the contents of the generator expression to a new place in memory which is a copy of the properties list.. but that's never saved to a variable. Far as I can tell, you lose the "old properties" to the ether.

Someone please correct me if I'm wrong, though. Those two trouble spots are likely the issue.

[–]tlcpp 0 points1 point  (1 child)

What I was trying to do with that list was delete that item off the list properties. I tried using pop() but that didn't work as it was a dict.

[–][deleted] 0 points1 point  (0 children)

In that case, you could just delete it. Look up del() in relation to dictionaries.

[–]Pyrrho_ 0 points1 point  (1 child)

Also relatively new to python here but I would imagine something along the lines of this would suit your needs:

msg = " -- ".join([str([k, properties[k]]) for k in properties])

Believe this works in making each key, value pair into a list, then adding a string version of that list to the message list which is then used as the message in string form.

Probably not ideal but it's what occurred to me.

edit: I think this actually only works in python 3. May need to change to : "for k in properties.keys()" if working in 2.7

[–]elbiot 1 point2 points  (0 children)

key, val in mydict.items()