SMTP Client example.
Display Number of available Messages in your Mail Box.
This example use incoming
Eth_V4_0 /
ENC_V4_0 library.
Code example :
Code: Select all
if dest_port_T = 110 then
begin
i := 0;
while i < 32 do
begin
getRequest[i] := Eth_GetByte;
inc(i);
end;
txt31 := '+OK Hello there.';
if Mem_Cmp(@getRequest, @txt31, Str_Len(txt31)) = 0 then
begin
len_tcp_resp := CopyRamStringToEthMem_CP('USER office@yahoo.com);
Eth_PutByte($0D);
Eth_PutByte($0A);
result := len_tcp_resp + 2;
exit;
end;
txt31 := '+OK Password required.';
if Mem_Cmp(@getRequest, @txt31, Str_Len(txt31)) = 0 then
begin
len_tcp_resp := CopyRamStringToEthMem_CP('PASS 7654TRGarT');
Eth_PutByte($0D);
Eth_PutByte($0A);
result := len_tcp_resp + 2;
exit;
end;
txt31 := '+OK logged in.';
if Mem_Cmp(@getRequest, @txt31, Str_Len(txt31)) = 0 then
begin
len_tcp_resp := CopyRamStringToEthMem_CP('STAT');
Eth_PutByte($0D);
Eth_PutByte($0A);
result := len_tcp_resp + 2;
exit;
end;
txt31 := '+OK Bye-bye.';
if Mem_Cmp(@getRequest, @txt31, Str_Len(txt31)) = 0 then
begin
result := 0;
exit;
end;
txt31 := '+OK ';
if Mem_Cmp(@getRequest, @txt31, Str_Len(txt31)) = 0 then
begin
i := 4;
while getRequest[i] <> ' ' do
begin
messages_nb[i-4] := getRequest[i];
inc(i);
end;
messages_nb[i-4] := 0;
len_tcp_resp := CopyRamStringToEthMem_CP('QUIT');
Eth_PutByte($0D);
Eth_PutByte($0A);
result := len_tcp_resp + 2;
exit;
end;
exit;
end;
main routine :
Code: Select all
begin
Eth_DoPacket;
if NTP_Sync = false then Ntp_query;
if TickCounter2 > 999 then
begin
TickCounter2 := 0;
Get_Time;
RemoveFirstNChr(TTime.Str, 10);
text_ := ' Time ';
Str_Cat(text_, TTime.Str);
LcdOut(2,1,text_);
end;
if count_mess > 600 then
begin
messages_nb := '-1';
if inc(TCP_opened_port) > 65000 then TCP_opened_port := 5000;
TCP_Open_Port(TCP_opened_port);
Open_TCP_Connection(user_ip_addr, dest_port, TCP_opened_port);
count_mess := 0;
while count_mess < 40 do
begin
Eth_DoPacket;
if messages_nb[0] <> '-' then break;
end;
text_ := 'You have ';
Str_Cat(text_, messages_nb);
Str_Cat(text_, ' new messages');
Str_Cat(text_, EOL);
Send_UDP(user_ip_addr1, 10003, eth_port, Str_Len(text_), text_);
TCP_Close_Port(TCP_opened_port);
TickCounter2 := 0;
if Str_Len(messages_nb) < 2 then Str_AppendPre(messages_nb, ' ');
LcdOut(1,1,messages_nb);
end;
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro