Code archives/Networking/BlitzMail Deluxe

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

Download source code

BlitzMail Deluxe by BlitzSupport2001
Hacked straight outta Mark's BlitzMail, this version performs error checking with the server, and is placed into a function for ease-of-plugging-in.
AppTitle "BlitzMail Deluxe"
Graphics 640, 480

; -----------------------------------------------------------------------------
; BlitzMail Deluxe -- adapted from Mark Sibly's BlitzMail code
; -----------------------------------------------------------------------------
; Sends an email message with decent error checking...
; -----------------------------------------------------------------------------
; ***** INSERT EMAIL ADDRESSES below, as specified! *****
; -----------------------------------------------------------------------------

Const DebugSMTP = 1					; Debug printout = 1
Color 0, 255, 0						; '80s hacker job...

; -----------------------------------------------------------------------------
; . User settings
; -----------------------------------------------------------------------------

	; ---------------------------------------------------------------------
	; SMTP server (CrossWind's is public, but use your own if known)
	; ---------------------------------------------------------------------
		Global mailhost$ = "smtp.crosswinds.net"

	; ---------------------------------------------------------------------
	; Email client name (this program)
	; ---------------------------------------------------------------------
		Global mailer$ = "BlitzMail Deluxe"
		
	; ---------------------------------------------------------------------
	; Sender's email address (***** INSERT YOUR ADDRESS *****)
	; ---------------------------------------------------------------------
		Global mailfrom$ = ""

	; ---------------------------------------------------------------------
	; Sender's real name
	; ---------------------------------------------------------------------
		Global mailname$ = "John Wayne"

; -----------------------------------------------------------------------------
; . Message data
; -----------------------------------------------------------------------------

	; ---------------------------------------------------------------------
	; Send message to this address (***** INSERT RECIPIENT'S ADDRESS *****)
	; ---------------------------------------------------------------------
		mailto$ = ""

	; ---------------------------------------------------------------------
	; Message to send (use | for newline)... keep it fairly short!
	; ---------------------------------------------------------------------
		message$ = "Hi there,||I think you'll agree, BlitzMail rules!||Your friend, John Wayne.|Sent via BlitzMail Deluxe"

; -----------------------------------------------------------------------------
; . Send message, show response ("BlitzMailed!" means success)
; -----------------------------------------------------------------------------

	reply$ = BlitzMail (mailto$, "BlitzMail Deluxe Test!", message$)
	Delay 1000: RuntimeError reply$
	End














; -----------------------------------------------------------------------------
; . SMTP functions
; -----------------------------------------------------------------------------



; -----------------------------------------------------------------------------
; BlitzMail...
; -----------------------------------------------------------------------------
Function BlitzMail$ (mailto$, subject$, message$)
	
	If debugSMTP Then Print "": Print "BlitzMailing...": Print ""
	
	message$ = Replace$ (message$, "|", Chr (13) + Chr (10))
	error$ = "BlitzMailed!"
		
	t = OpenTCPStream (mailhost$, 25)

	If t

		; ---------------------------------------------------------------------
		; Service available?
		; ---------------------------------------------------------------------
		response$ = ReadLine (t)
		code$ = Code (response$)
		If code$ <> "220"
			If code$ = "421"
				error$ = "Service not available"
			Else
				error$ = response$
			EndIf		
			Goto abortSMTP
		EndIf
		
		; ---------------------------------------------------------------------
		; Say "Hi"
		; ---------------------------------------------------------------------
		WriteLine t, "HELO BlitzMail Deluxe"
		response$ = ReadLine (t)
		If Code (response$) <> "250"
			error$ = response$
			Goto abortSMTP
		EndIf


		; ---------------------------------------------------------------------
		; Non-existent command -- try it for error message!
		; ---------------------------------------------------------------------
;		WriteLine t, "LALA BlitzMail Deluxe"
;		response$ = ReadLine (t)
;		If Code (response$) <> "250"
;			error$ = response$
;			Goto abortSMTP
;		EndIf


		; ---------------------------------------------------------------------
		; Tell server who's sending
		; ---------------------------------------------------------------------
		WriteLine t, "MAIL FROM: <" + mailfrom$ + ">"
		response$ = ReadLine (t)
		code$ = Code (response$)
		If code$ <> "250"
			If code$ = "501"
				error$ = "Email sender not specified (or invalid address)"
			Else
				error$ = response$
			EndIf
			Goto abortSMTP
		EndIf

		; ---------------------------------------------------------------------
		; Tell server who it's going to		
		; ---------------------------------------------------------------------
		WriteLine t, "RCPT TO: <" + mailto$ + ">"
		response$ = ReadLine (t)
		code$ = Code (response$)
		If code$ <> "250"
			If code$ = "501"
				error$ = "Email recipient not specified (or invalid address)"
			Else
				error$ = response$
			EndIf
			Goto abortSMTP
		EndIf

		; ---------------------------------------------------------------------
		; Email data
		; ---------------------------------------------------------------------
		WriteLine t, "DATA"
		response$ = ReadLine (t)
		If Code (response$) <> "354"
			error$ = response$
			Goto abortSMTP
		EndIf

		; ---------------------------------------------------------------------
		; Headers
		; ---------------------------------------------------------------------
		WriteLine t, "Date: "		+ CurrentDate$ ()
		WriteLine t, "From: "		+ mailname$ + " <" + mailfrom$ + ">"
		WriteLine t, "To: "			+ mailto$ + " <" + mailto$ + ">"
		WriteLine t, "Subject: "	+ subject$
		WriteLine t, "X-Mailer: "	+ mailer$

		; ---------------------------------------------------------------------
		; Email message
		; ---------------------------------------------------------------------
		WriteLine t, message$

		; ---------------------------------------------------------------------
		; End of message
		; ---------------------------------------------------------------------
		WriteLine t, ""
		WriteLine t, "."
		response$ = ReadLine (t)
		If Code (response$) <> "250"
			error$ = response$
		EndIf

		; ---------------------------------------------------------------------
		; Say "ciao"
		; ---------------------------------------------------------------------
		WriteLine t, "QUIT"
		response$ = ReadLine (t)
		If Code (response$) <> "221"
			error$ = response$
		EndIf

		; ---------------------------------------------------------------------
		; Return error message, if any
		; ---------------------------------------------------------------------
		.abortSMTP
		CloseTCPStream t
		If error$ = "" Then error$ = "Timeout error"
		Return error$
		
	Else

		; ---------------------------------------------------------------------
		; Oops. Forgot to go online (or server isn't there)	
		; ---------------------------------------------------------------------
		Return "Failed to connect to server at " + mailhost$
		
	EndIf
		
End Function

; -----------------------------------------------------------------------------
; Ask server for help (usually list of commands)... not much use, just example
; -----------------------------------------------------------------------------

Function GetHelp (server$)
	t = OpenTCPStream (mailhost$, 25)
	If t
		ReadLine (t) ; 220
		WriteLine t, "HELO BlitzMail Deluxe"
		ReadLine (t) ; 250
		WriteLine t, "HELP"
		response$ = ReadLine (t)
		error$ = Left (response$, 3)
		If error$ = "214"
			help$ = response$
			Repeat
				readhelp$ = ReadLine (t)
				help$ = help$ + Chr (10) + readhelp$
			Until readhelp$ = ""
			RuntimeError help$
		Else
			RuntimeError "Couldn't get help information!"
		EndIf
		CloseTCPStream (t)
	EndIf
End Function

; -----------------------------------------------------------------------------
; Return 3 digit code from server's response
; -----------------------------------------------------------------------------

Function Code$ (code$)
	If debugSMTP
		Print code$
	EndIf
	Return Left (code$, 3)
End Function

Comments

RifRaf2004
i get a timeout error everytime


dan_upright2004
i get a timeout error everytime
then you've probably set it up wrong or there's a problem with your mail server - the code works fine for me


RifRaf2004
; -----------------------------------------------------------------------------
; . User settings
; -----------------------------------------------------------------------------

; ---------------------------------------------------------------------
; SMTP server (CrossWind's is public, but use your own if known)
; ---------------------------------------------------------------------
Global mailhost$ = "smtp.msnhotmail.net"

; ---------------------------------------------------------------------
; Email client name (this program)
; ---------------------------------------------------------------------
Global mailer$ = "BlitzMail Deluxe"

; ---------------------------------------------------------------------
; Sender's email address (***** INSERT YOUR ADDRESS *****)
; ---------------------------------------------------------------------
Global mailfrom$ = "Aieroulis5@..."

; ---------------------------------------------------------------------
; Sender's real name
; ---------------------------------------------------------------------
Global mailname$ = "John Wayne"

; -----------------------------------------------------------------------------
; . Message data
; -----------------------------------------------------------------------------

mailto$ = "bigchance25@..."

message$ = "Hi there,||I think you'll agree, BlitzMail rules!||Your friend, John Wayne.|Sent via BlitzMail Deluxe"

reply$ = BlitzMail (mailto$, "BlitzMail Deluxe Test!", message$)

i have a hotmail accoutn, shouldnt the above work ok ?


BlitzSupport2004
Some SMTP servers require you to log into your POP3 account before they let you in. No idea if that's the case here, but it's (almost) definitely not the code causing timeouts!


Yan2004
I think Hotmail uses HTTP not SMTP.

[EDIT]Yup...webDAV...apparently[/EDIT]


YAN


RifRaf2004
OK GUYS I SET UP A CROSSWINDS ACCOUTN, I STILL GET THE TIMEOUT ERROR.. weird huh.. Why dont you have to enter a password to send mail.. i mean all yo need to know is someones account name and you an jack it to send emails?

here is how i set it up.. when i ran it "timeout error"

; ---------------------------------------------------------------------
; SMTP server (CrossWind's is public, but use your own if known)
; ---------------------------------------------------------------------
Global mailhost$ = "216.18.117.43"
;also tried smtp.crosswinds.net no go either that above is the straight ip for their smtp server.
; ---------------------------------------------------------------------
; Email client name (this program)
; ---------------------------------------------------------------------
Global mailer$ = "BlitzMail Deluxe"

; ---------------------------------------------------------------------
; Sender's email address (***** INSERT YOUR ADDRESS *****)
; ---------------------------------------------------------------------
Global mailfrom$ = "myaccountnamehere@..."

; ---------------------------------------------------------------------
; Sender's real name
; ---------------------------------------------------------------------
Global mailname$ = "Jeff Frazier"


Regular K2004
so what is hotmails address you would use for something like this?

smtp.msnhotmail.net ? Doesnt work


Craig Watson2004
Hotmail doesn't do SMTP.

Your Internet Service Provider should provide you with an SMTP server to use.


Jay Kyburz2005
anybody done logging into pop 3 and recieving mail as well?

dont wooryy found it here
http://www.blitzbasic.com/codearcs/codearcs.php?code=725


KuRiX2005
Hotmail requires logging in. To login you need to provide your user and password. No idea about how to send password's to an smtp server.


Code Archives Forum