Python Emailing - Use of colon causes no output
Really odd expe开发者_JAVA百科rience with this which took me over an hour to figure out. I have a cgi script written in python which takes form data and forwards it to an email, the problem was, if there was a colon in the string it would cause python to output nothing to the email.
Does anyone know why this is?
For example:
output = "Print- Customer"
works, though:
output = "Print: Customer"
prints no output.
My email function works essentially:
server.sendmail(fromaddr, toaddrs, msg)
where msg = output
Just wondering if the colon is a special character in python string output
Colon isn't a special character in python string output, but it is special to email headers. Try inserting a blank line in the output:
output = "\nPrint: Customer"
Allow me to make a few guesses:
- The mail is actually being sent, but the body appears to be empty (You question doesn't say this).
- You're not using the builtin python mailing library.
- If you open the mail in your mail reader, and look at the headers, the "
print:
" line will be present.
If so, the problem is that you're not ending the mail headers with a "\r\n
" pair, and the mail reader thinks that "print:
" is a mail header, while "print -
" is part of the body of a mal-formed email.
If you add the "\r\n
" after your headers, everything should be fine.
精彩评论