Tip: MailSend procedure
Posted: Wed Sep 11, 2002 7:15 am
Code updated For 5.20+
Restored from previous forum. Originally posted by PB.
Here's some old code I found that I cleaned up a bit and tested. Seems
to work fine with no problems, but doesn't support attachments.
Don't forget to change the settings at the end of the code to your own
ISP's server details!
PB - Registered PureBasic Coder
Restored from previous forum. Originally posted by PB.
Here's some old code I found that I cleaned up a bit and tested. Seems
to work fine with no problems, but doesn't support attachments.

Don't forget to change the settings at the end of the code to your own
ISP's server details!

Code: Select all
; MailSend procedure by PB -- do whatever you want with it.
; Stolen from an existing example but cleaned up by me a bit.
; Does not handle attachments because I don't know how. :(
;
Global MailID.l,MailResponse.s
;
Procedure MailDataSend(msg.s)
SendNetworkData(MailID,@msg,Len(msg))
EndProcedure
;
Procedure.s MailResponse()
MailResponse=Space(9999)
ReceiveNetworkData(MailID,@MailResponse,9999)
MailResponse=Left(MailResponse,3)
ProcedureReturn MailResponse
EndProcedure
;
Procedure MailSend(recipient$,subject$,body$,server$,from$)
If InitNetwork()
MailID=OpenNetworkConnection(server$,25)
If MailID0
MailResponse()
If MailResponse="220"
MailDataSend("HELO CGIapp"+Chr(13)+Chr(10))
MailResponse()
If MailResponse="250"
Sleep_(125)
MailDataSend("MAIL FROM: "+Chr(13)+Chr(10))
MailResponse()
If MailResponse="250"
MailDataSend("RCPT TO: "+Chr(13)+Chr(10))
MailResponse()
If MailResponse="250"
MailDataSend("DATA"+Chr(13)+Chr(10))
MailResponse()
If MailResponse="354"
Sleep_(125)
MailDataSend("Date: "+Chr(13)+Chr(10))
MailDataSend("From: "+from$+Chr(13)+Chr(10))
MailDataSend("To: "+recipient$+Chr(13)+Chr(10))
MailDataSend("Subject: "+subject$+Chr(13)+Chr(10))
Sleep_(125)
MailDataSend(body$)
Sleep_(125)
MailDataSend(""+Chr(13)+Chr(10))
MailDataSend("."+Chr(13)+Chr(10))
MailResponse()
If MailResponse="250"
Sleep_(125)
MailDataSend("QUIT"+Chr(13)+Chr(10))
MailResponse()
ProcedureReturn 1
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
CloseNetworkConnection(MailID)
EndIf
EndIf
EndProcedure
;
If MailSend("to@someone.com","Test","Did this work?","smtp.YOURISP.com.au","from@someone.com")
Debug "Mail sent successfully!"
Else
Debug "Error sending mail..."
EndIf
PB - Registered PureBasic Coder