Today many mail-servers require authentication before allowing you to send a mail. How this signalling is done I don't know but you can run the same commands as in the code by using Telnet to see...