Paulvk,
I approached mine a bit differently. He is the concept for SMTP, SNTP is the same. SMTP knows the port is 25, SNTP the port is hard code in the .lib for 37, NO-IP I am using port 80. This is just just test code for the created functions.
[code:1:72710d3920]
if Server_SMTPSendMsg("66.133.129.50") = true then 'send SMTP Email message
#if Debugflag
Print #Debugchannel,"Main, SMTP message sent."
#endif
Do
toggle tickbit ' flash heartbeat / tick timer LED FAST!!!!
waitms 50 ' indicate message sent
Loop
else
#if Debugflag
Print #Debugchannel,"Main, SMTP message not sent."
#endif
Set Tickbit ' turn off LED indicate Email NOT sent.
end 'Disable Interrupts and do nothing
endif[/code:1:72710d3920]
Server_SMTPSendMSG calls Server_ServerInit which does the following.....IPaddress comes from the call above, just passed down. There is more code to the Server_ServerInit routine but you get the idea here. Really easy to load configuration data from a file and setup the passed parameters.
[code:1:72710d3920]
'
' Convert string IP to an array of bytes
'
b = Split( IPaddress , strIP(1) , "." )
for a = 1 to b
'Print #Debugchannel, b;" = ";val(strIP(a))
bytIP(a) = val(strIP(a)) 'string to value
next a
lngIPcon = Maketcp(bytIP(1) , bytIP(2) , bytIP(3) , bytIP(4) ) ' server
IPadr = ip2str(lngIPcon)
[/code:1:72710d3920]
The high level routines are pretty simple to follow. The lower lever routines monitor sever response and pass status back to caller. Gets fairly verbose, so I bury them so I don't have to look at them.
Looks like this.....Most SMTP servers require authentication, so I have added that in to my calls, BASE64 encrypted and the username/password is read from the [SMTP] section of the configuration file on the uSD along with all server and mailer information.
[code:1:72710d3920]
Function Server_SMTPSendMsg(byval IPaddress as string ) as byte
'
' This function is the top level entry routine to send a SMTP message.
' Status is retained through the whole process and can be logged if desired.
'
' Returned status : 0 = message not sent. 1 = message sent.
'
local a as byte ' remember status
a = 0 ' default to message not sent
if Server_ServerInit(IPaddress , 25 ) = true then ' create/connect socket X port 25 to SMTP server
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, Connection Established to SMTP server."
#endif
if Server_SMTPlogin() = true then '
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP Login PASSED."
#endif
if Server_SMTPtoFROM() = true then
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP To/From Email addresses PASSED validation."
#endif
if Server_SMTPBodyMSG() = true then
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP message was sent SUCCESSFULLY."
#endif
a = 1 ' indicate message sent
else
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP message FAILED to be sent."
#endif
endif
else
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP To/From Email addresses FAILED validation."
#endif
endif
else
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, SMTP Login FAILED";
#endif
endif
else
#if debugflag
print #Debugchannel,"Server_SMTPSendMsg, connection to SMTP server not established";
#endif
endif
'#if debugflag
' Print #Debugchannel, "Server_SMTPSendMsg, disconnecting and closing socket ";bytI
' #endif
Call Server_CloseSocket() 'close socket
Server_SMTPSendMsg = a ' return status to caller
End Function
[/code:1:72710d3920]
Regards,
Mark
↧