[erlang-questions] Odd behavior when sending emails via SMTP when messages are converted to/from binaries

Chris Hicks silent_vendetta@REDACTED
Sun May 15 02:18:06 CEST 2011


In the system I'm building I am working with all my strings as binaries. I'm doing this because I'll be deploying on a 64 bit platform and don't need all the text I'm working with blowing up in size when there isn't any need for it. However I'm noticing an odd behavior when constructing emails to send over SMTP.
Basically what I'm doing is this:...Message_body = "This is a message body", <-- This part is actually more complex in that variables are being used along with string literals to form the entire body, which is why I initially create it as a string.
Binary_message = erlang:term_to_binary(Message_body),
email:send(Binary_message).

The other module then does this:...Header = "From: xxx <xxx>\rTo: yyy<yyy>\rSubject: This is the subject\r",
Full_message = Header ++ erlang:binary_to_list(Binary_message),
send_email(Full_message).

Now the message sends just fine and shows up in my email. However in front of the Message_body text are three extra characters "ƒkŐ" and if I change the second module to this:...Header = "From: xxx <xxx>\rTo: yyy<yyy>\rSubject: This is the subject\r",Body = erlang:binary_to_list(Binary_message),
Full_message = Header ++ Body,send_email(Full_message).

Then the three characters change to these"ƒk×" and I simply can't figure out what is going on. Now I'm not building a mail server and I don't expect to be sending thousands of emails so working around this by simply treating all email text as strings (not converting to/from binary) is certainly not a problem. I am just curious if anyone can explain or help me figure out what is going on.
Chris Hicks.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110514/b1aa38a0/attachment.htm>


More information about the erlang-questions mailing list