Simplest networking library? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- vicot · 2013-12-24 09:40 What is the simplest (easiest to use) socket library available for Lazarus programmers? I only need it for sending emails via SMTP and to retrieve emails via POP3. Thanks ---------------------------------------------------------------------- jarto · 2013-12-24 10:59 If you need to retrieve e-mails too, then probably Indy is the way to go. ---------------------------------------------------------------------- Laksen · 2013-12-24 11:05 You could try Indy, lNet, or synapse. Synapse is probably the simplest of the two. Indy might have support for more protocols though ---------------------------------------------------------------------- vicot · 2013-12-24 12:08 Quote from: Laksen on December 24, 2013, 12:05:28 pmYou could try Indy, lNet, or synapse. Synapse is probably the simplest of the two. Indy might have support for more protocols though I forgot to mention: I do need the SSL/TLS support. I looked into Synapse, and it says that for SSL/TLS support, the code needs to be modified. I am unable to modify it by myself, so I am asking: does anyone have an already modified version of Synapse? Or is Indy the only option open to me? Thanks again ---------------------------------------------------------------------- BigChimp · 2013-12-24 12:14 Yes, there are libraries that provide it. Search the forum and the wiki; as an example there's IIRC a package made in Brazil that provides smtp with ssl support based on synapse. Edit: see also posts like this http://forum.lazarus.freepascal.org/index.php/topic,21157.msg123501.ht ml#msg123501 Contributions to http://wiki.lazarus.freepascal.org/synapse welcome as well ---------------------------------------------------------------------- jarto · 2013-12-24 18:03 Sure, Synapse does support SSL but I don't think that it has a component for reading POP3 mail. ---------------------------------------------------------------------- mica · 2013-12-25 06:35 http://synapse.ararat.cz/doc/help/pop3send.TPOP3Send.html http://synapse.ararat.cz/doc/help/ ---------------------------------------------------------------------- jarto · 2013-12-25 08:06 I stand corrected. Thanks mica :-) ---------------------------------------------------------------------- arneolav · 2013-12-25 09:55 Hi! I'm using Synapse, SMTP with good lock. I modified the SmtpSend.pas a little, did put the TargetPort as a param: Code: [Select]function SendToRaw(const MailFrom, MailTo, SMTPHost: string; const MailData: TStrings; const Username, Password, TargetPort: string): Boolean; // < -------TargetPort--- ao 2013.11.02 var SMTP: TSMTPSend; s, t: string; begin Result := False; SMTP := TSMTPSend.Create; try // if you need SOCKS5 support, uncomment next lines: // SMTP.Sock.SocksIP := '127.0.0.1'; // SMTP.Sock.SocksPort := '1080'; // if you need support for upgrade session to TSL/SSL, uncomment next lines: // SMTP.AutoTLS := True; // if you need support for TSL/SSL tunnel, uncomment next lines: // SMTP.FullSSL := True; SMTP.TargetHost := Trim(SeparateLeft(SMTPHost, ':')); s := Trim(SeparateRight(SMTPHost, ':')); if (s <> '') and (s <> SMTPHost) then SMTP.TargetPort := s; SMTP.Username := Username; SMTP.Password := Password; SMTP.TargetPort := TargetPort; //'587'; // < -------TargetPort--- ao 2013.11.02 if SMTP.Login then begin if SMTP.MailFrom(GetEmailAddr(MailFrom), Length(MailData.Text)) then begin s := MailTo; repeat t := GetEmailAddr(Trim(FetchEx(s, ',', '"'))); if t <> '' then Result := SMTP.MailTo(t); if not Result then Break; until s = ''; if Result then Result := SMTP.MailData(MailData); end; SMTP.Logout; end; finally SMTP.Free; end; end; function SendToEx(const MailFrom, MailTo, Subject, SMTPHost: string; const MailData: TStrings; const Username, Password, TargetPort: string): Boolean; // < -------TargetPort--- ao 2013.11.02 var t: TStrings; begin t := TStringList.Create; try t.Assign(MailData); t.Insert(0, ''); t.Insert(0, 'X-mailer: Synapse - Delphi & Kylix TCP/IP library by Lukas Gebauer'); t.Insert(0, 'Subject: ' + Subject); t.Insert(0, 'Date: ' + Rfc822DateTime(now)); t.Insert(0, 'To: ' + MailTo); t.Insert(0, 'From: ' + MailFrom); Result := SendToRaw(MailFrom, MailTo, SMTPHost, t, Username, Password, TargetPort); finally t.Free; end; end; usage: (Plain SMTP, no SSL/TLS) uses smtpsend...... function SendMail : Boolean; var MailData: TStrings; begin MailData := TStringList.Create; try MailData.Add(...your mail text... ); Result:= SendToEx(MailFrom, MailTo, Subject, SMTPHost, MailData, Username, Password, TargetPort); finally t.Free; end; end; You can find SMTP with TLS/SSL at http://wiki.lazarus.freepascal.org/Synapse#Sending_email Synapse: http://www.ararat.cz/synapse/doku.php/public Syapse was fast and easy to implement, but as far as I can see its missing the posibility of sending Attachment. In Delphi I did use Indy, SMTP and PoP3. (Have not tried PoP3 in Lazarus). ---------------------------------------------------------------------- jarto · 2013-12-25 10:31 In the famous style of Fermat, I've found a great solution for attachments with Synapse but don't have the time to write it down here :-) Basically, you need to build the message as a TMimeMess and add the e-mail text and attachments to it with AddPartTextEx and AddPartMultipart. Sorry for being brief. ---------------------------------------------------------------------- arneolav · 2013-12-25 11:43 Yes, I'v been looking at it, but i had expected Mail Attachment built in into SmtpSend in Synapse.... ---------------------------------------------------------------------- BigChimp · 2013-12-25 12:37 http://lmgtfy.com/?q=synapse+smtp+attachment gives http://synapse.ararat.cz/doku.php/public:howto:tmimepart Good luck. ---------------------------------------------------------------------- arneolav · 2013-12-25 21:34 Thanx, then I'v implemented myself... Send e-mail SMTP with Attachment, using Synapse; Using modified smtpsend.pas look above. Code: [Select]unit smtpsend; . . uses .... mimemess, mimepart; function SendAttach(const MailFrom, MailTo, Subject, SMTPHost: string; const MailData: TStrings; const Username, Password, TargetPort, AttachFile: string): Boolean; implementation . . . . function SendAttach(const MailFrom, MailTo, Subject, SMTPHost: string; const MailData: TStrings; const Username, Password, TargetPort, AttachFile: string): Boolean; var m:TMimemess; l:tstringlist; p: TMimepart; begin m:=TMimemess.create; l:=tstringlist.create; try { p := m.AddPartMultipart('mixed', nil); l.loadfromfile('c:\search.log'); m.AddPartText(l,p); m.AddPartBinaryFromFile('c:\search.log',p); m.header.from:='youraddress@somewhere.com'; m.header.tolist.add('You@somewhere.com'); m.header.subject:='test message'; m.EncodeMessage; //memo1.lines.assign(m.lines); if you wish to send it by SMTP too, then: SendToRaw('youraddress@somewhere.com', 'You@somewhere.com', 'your.smtp.server.com', m.lines, 'yourusername', 'yourpassword', 'TargetPort'); } p := m.AddPartMultipart('mixed', nil); l.loadfromfile(AttachFile); m.AddPartText(l,p); m.AddPartBinaryFromFile(AttachFile,p); m.header.from:=MailFrom; m.header.tolist.add(MailTo); m.header.subject:=Subject; m.EncodeMessage; Result := SendToRaw(MailFrom, MailTo, SMTPHost, m.Lines, Username, Password, TargetPort); finally m.free; l.free; end; end; usage: var t: TStrings; t.Add(your mess body text); SendAttach(SenderEmail, ReciptEmail, 'Subject', SmtpServerName, t, SmtpServerUser, SmtpServerPassword, inttostr(SmtpServerPort), AttachmentFileName); Tested, ok. ---------------------------------------------------------------------- arneolav · 2013-12-26 15:26 Download Synapse: http://synapse.ararat.cz/doku.php/download Download unit smtpclientlib: https://code.google.com/p/easy-synapse- smtpclient/source/browse/smtpclientlib_v2.pas Sample usage: Code: [Select]uses ... smtpclientlib; procedure TForm1.ButtonClick(Sender: TObject); var oSmtpClient: TSmtpClient; begin oSmtpClient := TSmtpClient.Create; try oSmtpClient.ServerAdress := 'smtp.mandrillapp.com'; ->>>error: oSmtpClient.ServerDomain := 'smtp.mandrillapp.com'; oSmtpClient.ServerPort := '587'; oSmtpClient.ServerLoginUsername := 'me@here.com'; oSmtpClient.ServerLoginPassword := 'difficult-and-long- password'; oSmtpClient.MessageClear; oSmtpClient.BodyAsPlainText.Text := 'Plain body text.'; oSmtpClient.BodyAsHtml.Text := '
';
oSmtpClient.AddInlineAttachment(
'C:\lazarus\examples\jpeg\lazarus.jpg' );
oSmtpClient.AddAttachment( ExtractFilePath( ParamStr( 0 ) ) +
'project1.lpi' );
if oSmtpClient.Send( 'info@company.com', //mailfrom
'you@there.com', //mailto
'', // copy to
'', // copy to
'Subject ... Buy more of our stuff' )
//Subject
then
ShowMessage( 'Send ok' )
else
ShowMessage( oSmtpClient.SendResult );
finally
oSmtpClient.Free;
end;
end;
You may copy Snyapse.pas -files into your directory (simpel way),
Better: Setup a path to your Synapse directory
----------------------------------------------------------------------
vicot · 2013-12-26 20:39
It would be nice if one of you guys (perhaps the maintainer of Synapse
himself) released an updated version of Synapse featuring integrated
support for attachments too.
Many newbies would not dare messing up with code to add a feature that
is not officially supported.
Work on an all-inclusive new release would be very much appreciated.
Thanks.
----------------------------------------------------------------------
arneolav · 2013-12-26 21:03
Agree!
----------------------------------------------------------------------
Leledumbo · 2013-12-27 06:17
QuoteIt would be nice if one of you guys (perhaps the maintainer of
Synapse himself) released an updated version of Synapse featuring
integrated support for attachments too. Tell the author then, not here
(well, except the author is here and see this thread)
----------------------------------------------------------------------
BigChimp · 2013-12-27 09:01
Quote from: Leledumbo on December 27, 2013, 07:17:11 amQuoteIt would
be nice if one of you guys (perhaps the maintainer of Synapse himself)
released an updated version of Synapse featuring integrated support
for attachments too. Tell the author then, not here (well, except the
author is here and see this thread)
1. Very much agreed.
2. I *very strongly* suspect the Synapse author does not read this
forum. He is open to having patches posted on his mailing list.
----------------------------------------------------------------------
vicot · 2013-12-27 13:19
While browsing the Synapse website looking for the author's email
(BTW, I could not find his email - does anyone have it?), I discovered
something that looks a bitt worrying (for my needs):
QuoteThe whole library is oriented on the WIN32 environment or Linux
enviroment, so you will need Delphi 3.0 or higher and Kylix 1.0 or
higher to use it. However some new ports for FreePascal are available
too.
Does this really mean, as it would seem, that we are required to use
Delphi or Kylix (depending on the OS), in order to use Synapse?
----------------------------------------------------------------------
BigChimp · 2013-12-27 13:29
1. Use the mailing list as Lukas suggests on his site.
2. Is that a serious question? Have you seen how many FPC/Lazarus
projects use Synapse? I use it myself and it works just fine. It's
most probable that Lukas didn't update that page but focused on say...
coding.