Code archives/Networking/BlitzMail

This code has been declared by its author to be Public Domain code.

Download source code

BlitzMail by marksibly2001
This code will send an email.

Its pretty rude - doesn't check for errors or responses - but appears to work!

Note that the '<>' around the addresses are required, and that the message is terminated by sending the "" and "." lines.
t=OpenTCPStream( "smtp.yourisphere",25 )
If Not t RuntimeError( "Error connecting" )
WriteLine t,"HELO BlitzMail"
WriteLine t,"MAIL FROM: "
WriteLine t,"RCPT TO: "
WriteLine t,"DATA"
WriteLine t,"Hello there Mark!"
WriteLine t,"This is from Blitz Mail!"
WriteLine t,""
WriteLine t,"."
WriteLine t,"QUIT"
Print "Done. Press any key...":WaitKey

Comments

Warren2004
Hey, cool! I was wanting to do a "tell a friend" button on the main menu of my next game. I want it to send an email to the address the user provides ... this is perfect!

Thanks!

-- although it looks like some of your '<>' markers got cleared out by the code display.


dangerdave2004
Beware of course, that user's firewall, antivirus may interrupt the process and wreak havoc on a full screen program.


Warren2004
I just tackled that in my game actually, in regards to the online high score board.

If the game is running fullscreen, it drops down to windowed mode for the "connect to the internet and upload/download high scores" procedure. It then pops back into fullscreen once finished.


Warren2004
Has anyone gotten this to work? It claims to send the mail but I never get it...


electronin2004
I'm having the same problem. The mail never actually arives :(


Warren2004
For those interested, you can stick this piece of code just before the last line to read any output from the mail server:
Not Eof(t)
	Print ReadLine$( t )
Wend

I get messages from some servers saying routing is not allowed, but others don't say a thing. I never get the email at any rate...


Craig Watson2004
You can never expect this to realistically work for a game.

You will need the user to enter their own SMTP server address, because as you have noted SMTP servers tend to be locked to your local IP group.

This is done to make spamming harder.

There are some ways around it, but a much better idea would be to call a Perl/CGI/Whatever script on your webserver that sends mail. You could also customise the script specifically for the purposes of marketing your game so it would be of less interest to hackers.


Warren2004
Yeah, I've decided to use a PHP script on my server now instead. Ahh well... :)


GNS2004
I had problems implementing this in the past. I did some research and found my mail server supports the 'ESMTP' protocol. I looked over the ESMTP RCC docs and modified the above to work with my mail server/support the ESMTP protocol to a certain extent.

Oddly enough, the only thing preventing the above example from supporting 'basic' ESMTP is an 'EHLO' (yes, 'EHLO') command.

With that said, using a web-based solution is probably the best idea. With all of these obscure mail protocols floating around there's no telling what type Player A's mail server supports.

Oh, and for the curious soul, here's my modified example:

;ESMTP Protocol Test

;Notes on the ESMTP Protocol:
;-To see a list of features the server supports, send the server a "HELP" command
;-Each server message is prefixed with a 3 digit code. Certain codes represent error messages, etc.
;and can be parsed to determine the error. 
;-Common error codes Include:
;421 -> SMTP server no longer available
;500 -> 'EHLO' command is not supported (server doesn't support ESMTP)
;501 -> 'EHLO' arguement not acceptable
;502 -> Server unnable to implement 'EHLO' command
;504 -> Unknown error


streamin = OpenTCPStream(Input("Enter SMTP Server: " ), 25) ;assumed port 25 (standard port)

If Not streamin
	RuntimeError("Server not found.")
EndIf

mailFrom$ = Input("Enter From Address: ")
mailTo$ = Input("Enter To Address: ")
message$ = Input("Enter Mail Message (\n for new line): ")
message$ = Replace$(message$, "\n", Chr$(13)+Chr(10))

If streamin
	WriteLine streamin, "EHLO ESMTPTest" ;seems to be the only thing separating SMTP from being ESMTP on the client side
	
	DebugLog ReadLine(streamin) ;should acknowledge 'EHLO' (what an odd greeting..)
	
	WriteLine streamin, "HELO ESMTPTest"
	
	WriteLine streamin, "MAIL FROM:<" + Trim$(mailFrom$) + ">"
	
	DebugLog ReadLine(streamin)
	
	WriteLine streamin, "RCPT TO:<" + Trim$(mailTo$) + ">"
	
	DebugLog ReadLine(streamin)
	
	WriteLine streamin, "DATA"
	
	DebugLog ReadLine(streamin)
	
	WriteLine streamin, message$
	
	WriteLine streamin, " "
	
	WriteLine streamin, "."
	
	WriteLine streamin, "QUIT"
	
	DebugLog ReadLine(streamin)
	
	CloseTCPStream(streamin)
	
EndIf

WaitKey()



Regular K2004
I'd love to use something like this for my game, for reporting bugs.

But I dont know the SMTP server I would use.

My ISP is Shaw
My email is by Hotmail

Can anyone help me?


Craig Watson2004
Apparently you can just use "shawmail" (minus quotes) as your SMTP server. Also check here if that doesn't work.


Regular K2004
Ill keep trying.
My email is with hotmail, how can I get this to work!?


RGR2004
If this would be that easy you could send spam under any hotmail email address you know.
I guess you must provide your password to the mail server first to be able to send anything that way.
For hotmail smtp server "mail.hotmail.com" in the connection line works - it accepts; but does not send anything due to no proper identification (Username? Password?).


chwaga2007
lets say my email is fakeemail@... and my smtp is smtp-server.com. How could i send a mail to myself for bug reports?


Code Archives Forum