SRL Archive - Delphi/FPC Help and Tutorials

Email


xdarkshadowx

2012-12-31 19:17:46

Are there any email functions or library's available in free-pascal?

Justin

2012-12-31 19:53:05

From: xdarkshadowx
Are there any email functions or library's available in free-pascal?


AFAIK; Not built in simba, a workaround would be to host a .php mailscript and then using the 'AddPostVariable' and 'PostHTTPPageEx' methods in Simba to send the email from the website

Brandon

2012-12-31 23:07:49

It is built into Simba. You can also use a library called Synapse or Indy for FreePascal/Lazarus. I believe Simba uses Synapse internally.. But it is possible to send an email via Simba. Just need knowledge of Sockets and the mail header..


This is as far as I could get.. I cannot figure out how to login with Simba.. There's very little documentation on the AUTH command through sockets and almost none for Simba's Sockets. Maybe someone else will shed some light..

I somehow got further with Hotmail than with Gmail.. I got it working in C++ using Winsocks (took forever!!).. Just can't do it in Simba :l



Procedure SendSocketEx(Socket: Integer; Message: String);
begin
SendSocket(Socket, Message + #13#10);
end;

Procedure SendEmail(UserName, Password, IP, Port, YourIP: String);
var
Socket: Integer;
Begin
Socket := CreateSocket;
ConnectSocket(Socket, IP, Port);
SetTimeout(Socket, 10000);
SocketInfo(Socket, IP, Port);

writeln('Connected to: ' + IP + ' Port: ' + Port);
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'HELO');
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'STARTTLS');
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'MAIL FROM: <mehwtfbleh@hotmail.com>');
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'VRFY <mehwtfbleh@hotmail.com>');
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'RCPT TO: <mehwtfbleh@hotmail.com>');
writeln(RecvSocket(Socket));

SendSocket(Socket, 'DATA' + #13#10 + '.' + #13#10);
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'This Is The Body..');
writeln(RecvSocket(Socket));

SendSocketEx(Socket, 'QUIT');
writeln(RecvSocket(Socket));

CloseSocket(Socket);
FreeSocket(Socket);
End;

begin
ClearDebug;
SendEmail('', '', 'smtp.live.com', '25', 'localhost');
end.

And the above will print (throws exception when sending "DATA" string:


Connected to: 65.55.172.254 Port: 25
220 BLU0-SMTP43.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Mon, 31 Dec 2012 20:10:29 -0800

250 BLU0-SMTP43.blu0.hotmail.com Hello [50.100.44.155]

220 2.0.0 SMTP server ready

Exception: Socket Error 10054: Connection reset by peer
Socket[0] has not been freed in the script, freeing it now.



Same for google:


SendEmail('', '', 'smtp.gmail.com', '587', 'localhost');


Connected to: 74.125.133.109 Port: 587
220 mx.google.com ESMTP uz1sm35049381igb.16

250 mx.google.com at your service

220 2.0.0 Ready to start TLS

Exception: Socket Error 10054: Connection reset by peer