Blitz sending e-mails!?!

Blitz3D Forums/Blitz3D Programming/Blitz sending e-mails!?!

Craig H. Nisbet(Posted 2005) [#1]
Any one know if it's possible?


slenkar(Posted 2005) [#2]
SOmeone may have done it at blitzcoder
dont use google to search the website because youll get loads of useless entries


GfK(Posted 2005) [#3]
http://www.blitzbasic.com/codearcs/codearcs.php?code=23


John Pickford(Posted 2005) [#4]
I'm doing it in my game using code based on Marks Blitzmail. It works very well indeed. I'm even sending attached files.


BlitzSupport(Posted 2005) [#5]
Beware of using this for public stuff, though -- many people won't know what the heck their SMTP server settings should be, and a lot of ISPs' SMTP servers will actually reject attempts to send email through them unless you've accessed the POP3 server within a certain time-frame...


John Pickford(Posted 2005) [#6]
How else can I send emails from my game?

I haven't encountered any problems with it so far BTW.


GfK(Posted 2005) [#7]
I'm doing it in my game using code based on Marks Blitzmail. It works very well indeed. I'm even sending attached files.
I'm curious - what sort of game would you want to send e-mails from?


John Pickford(Posted 2005) [#8]
A turn based game.


Warren(Posted 2005) [#9]
Or a "Tell A Friend" feature.


John Pickford(Posted 2005) [#10]
No, it's definitely a turn based game.

;-)


BlitzSupport(Posted 2005) [#11]
JP: This is what I get if I try to send email using the 'BlitzMail Deluxe' code, as linked to by Gfk up there ^^^. It's just BlitzMail with some error checking...



If I log into my POP3 account (ie. receive email) first, it'll let me send via SMTP for a given amount of time after that. There's some code here to access POP3 email (it doesn't have to be downloaded, just accessed). There's no way around it as this sort of thing is put in place by individual ISPs.

It does add more complication to the end user, though, as you need to know your SMTP and POP3 server details, and enter your username/password for POP3; in fact, looking at that, you might need to access an IMAP account for some users to be able to send, and I know nothing about that.

I'm only bringing this up as it will obviously cause problems for your game on release if this happens. I assume that your own ISP doesn't require you to log into your POP3 email before accessing your server, which would explain why you haven't run into problems (though if you leave your email client working all the time it'll be doing the POP3 access for you -- try running your game after leaving your email program closed for a good while).

The only way I could see this being made easy on the end user would be if you ran your own mail server for your game's users to connect through, but that opens a can of worms, too, as I don't think you can password-protect SMTP servers (I imagine ISPs allow access based on your IP address being one of theirs, or something like that), so it'd be an open relay (ideal for spammers).

Sorry if this screws things right up, but unless anyone knows better, I do think you'll find yourself running into this! I have some ideas for working around this (eg. a central server taking direct messages from the clients and then sending out the emails to registered users), but they'd be outside my abilities to implement...


Knotz(Posted 2005) [#12]
I would use a webserver to pass messages in a turn based game.

a call like this:

http://www.foo.com/cgi-bin/msg.cgi?to=somebody&else=me&subject=whatever&body=hi

You can easily store the messages in a database for the other player to be picked up.

No configuration for the user, easy and transparent solution. You have to think a bit about security and privacy though.


John Pickford(Posted 2005) [#13]

Sorry if this screws things right up, but unless anyone knows better, I do think you'll find yourself running into this! I have some ideas for working around this (eg. a central server taking direct messages from the clients and then sending out the emails to registered users), but they'd be outside my abilities to implement...


Cheers for the info. We haven't encountered that on any PC we've tried it on yet.

I don't think it screws things up. We can add the pop 3 stuff as a backup option. Its not the end of the world if some people can't get it working. Email play is only one aspect of the game.


John Pickford(Posted 2005) [#14]
We are looking at using a server to handle outgoing turns anyway. The main reason is more to do with 'match making' and allowing people to play strangers without revealing their email address. But I'm committed to Email for 'incoming' turns. I think it works a lot better as you don't need to have the game running to know a turn has arrived - far more inclusive and more fun.

James, I'm starting the first phase of testing next week, mainly for the Email game. Do you want to be a tester?


BlitzSupport(Posted 2005) [#15]

Do you want to be a tester?


Yep, sure, I'll give it a whirl!


Beaker(Posted 2005) [#16]
I did a few (non-blitz) applications that sent e-mails. The biggest problem by far was that some accounts had very tight spam controls (hotmail, yahoo etc) and would often not accept or would file them under spam.

I sorted it in the end but it meant having special rules (and simpler e-mails) for those type of accounts. Pain really.


Craig H. Nisbet(Posted 2005) [#17]
Well I tried the test code that GFK posted and it work! Now the next trick is how to get it to send a file attatchment. Any ideas?


John Pickford(Posted 2005) [#18]
Here you go.

This bit goes into Blitzmail, It's ages since I worked on this. message$ is the path of a text file which forms the email content. attachpath$ & attach$ point to the binary file you want to attach.


; ---------------------------------------------------------------------
; Email message
; ---------------------------------------------------------------------



	WriteLine t,"Content-Type: multipart/mixed; boundary="+Chr$ (34)+"boundarystring"+Chr$(34)
	
	  WriteLine t,""
	  WriteLine t,"--boundarystring"
	  WriteLine t,"Content-Type: text/plain" 
	  
	  mess=OpenFile (message$)
	
	  If mess
	
	
		While Not Eof (mess)
		
		 mbyte=ReadByte (mess)
		
		 If mbyte=Asc ("#")
		
			Select ReadByte(mess)
			
				Case Asc ("1")
				
				  WriteString t,mailto$
				
				Case Asc ("2")
				
				  WriteString t,mailname$
			
			
			End Select
		
		 Else
		
		
		  WriteByte t,mbyte
		 
		EndIf
		
		
		Wend
	
	
		CloseFile (mess)
	  EndIf
		
	
			
	  encode_file (attachpath$,attachment$,t)
	
	  WriteLine t,""
	  WriteLine t,"--boundarystring--"
	
	
	
	


And this is the function it calls to encode the file


Function encode_file (path$,name$,stream)

	DebugLog "Encoding file attachment"
	
	file=OpenFile (path$+name$)

    If file

;Info

	WriteLine stream,""
	WriteLine stream,"--boundarystring" 
	WriteLine stream,"Content-Type: application/octet-stream; name="+name$
	WriteLine stream,"Content-Transfer-Encoding: base64"
	WriteLine stream,"Content-Disposition: attachment; filename="+name$ 
	WriteLine stream,""


	linelen=0

	While Not Eof (file)

;Fetch 3 bytes

		
		value=ReadByte (file) 
		value=(value Shl 8) Or ReadByte (file)
		value=(value Shl 8) Or ReadByte (file)

	
;spit out 4 bytes (encoded)
	
		WriteByte stream,Asc(Mid$ (encodestring$,1+ ( (value Shr 18) And 63) ) )
		WriteByte stream,Asc(Mid$ (encodestring$,1+ ( (value Shr 12) And 63) ) )
	    WriteByte stream,Asc(Mid$ (encodestring$,1+ ( (value Shr 06) And 63) ) )
		WriteByte stream,Asc(Mid$ (encodestring$,1+ ( (value Shr 00) And 63) ) )


		;new line every 64 chars
	
		linelen=linelen+4
	
		If linelen>63
		
			WriteLine stream,""		
			linelen=0
		EndIf
		
		    
	Wend
	
	CloseFile (file)
	
	Else
	
		DebugLog "File not found"
	
	EndIf
	
End Function



Craig H. Nisbet(Posted 2005) [#19]
GFK example shows how to send a string as an e-mail. This second johns version is sending a text file as the e-mail body. How do I get the text file to be sent as the e-mail body. Is this Blitzmail code somewhere where I can see it?