Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-05

Sending e-mail from within Lazarus

11 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brian

Does anybody have a working example of sending e-mail from a Lazarus program through their ISP's mail server (which requires SSL/TLS) that they'd be willing to share with me? I've been trying to follow Michael's writeup for using Synapse, I'm getting a timeout error from deep within the Synapse code, and I don't know whether it's something that I've screwed up or some kind of incompatibility with the mail server - my ISP, of course, will only tell me to use Outlook or similar. :( If I try to step through with the debugger, I get a socket error of 110. The version of Synapse I'm using is (I think) 40.1, at least it's the version downloaded via the online package manager.

I'm using Lazarus 1.8.2 and FPC 3.0.4 as downloaded from SourceForge.

Thanks.

Reply by email

Carlos E. R.
to Brian
Brian wrote
Does anybody have a working example of sending e-mail from a Lazarus program through their ISP's mail server (which requires SSL/TLS) that they'd be willing to share with me?

I intend to code this soon, but I will simply call "mailx", an external program to do it. The classic method was to call the sendmail binary.

I use Linux, you did not say what you use.

Cheers / Saludos, Carlos E. R. (from 42.3 x86_64 "Malachite" at Telcontar) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 181 bytes Desc: OpenPGP digital signature URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180510/6d6e5685/attachment.sig>

Reply by email

Unknown author
to Carlos E. R.
Carlos E. R. wrote 9 lines
On 2018-05-10 15:31, Brian via Lazarus wrote: > Does anybody have a working example of sending e-mail from a Lazarus > program through their ISP's mail server (which requires SSL/TLS) that > they'd be willing to share with me? I intend to code this soon, but I will simply call "mailx", an external program to do it. The classic method was to call the sendmail binary. I use Linux, you did not say what you use.

In addition to Carlos' suggestion, and if you use Windows, you could use Blat [1] or even Powershell [2] to do this. It will not be "native", but it works.

I used to use perl (I have been completely addicted to it for non-GUI stuff for decades now) or "The Bat!" in the past for this, but I don't know if "The Bat" still exists.

[1] https://sourceforge.net/projects/blat/

[2]
https://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/

Grx HdV

Reply by email

Brian
to Carlos E. R.: I intend to code this soon, but I will simply call "mailx", an external program to do it.…
Carlos E. R. wrote 10 lines
On 2018-05-10 15:31, Brian via Lazarus wrote: > Does anybody have a working example of sending e-mail from a Lazarus > program through their ISP's mail server (which requires SSL/TLS) that > they'd be willing to share with me? I intend to code this soon, but I will simply call "mailx", an external program to do it. The classic method was to call the sendmail binary. I use Linux, you did not say what you use.

Ugh, sorry. 64-bit Ubuntu Studio 16, LTS.

Reply by email

Denis Kozlov
to Brian: Does anybody have a working example of sending e-mail from a Lazarus program through…

Try the latest trunk version of Synapse code:
http://sourceforge.net/p/synalist/code/HEAD/tree/trunk/

You'll also need OpenSSL binaries:
https://wiki.openssl.org/index.php/Binaries

Here is a snippet of a working connection routine, although tested in Delphi only:

================================================

uses
  // "ssl_openssl" unit is required to use SSL / TLS   mimemess, mimepart, synachar, ssl_openssl;

type
  TMailerSecurity = (
    msNONE,
    msSTARTTLS,
    msSSLTLS
  );

procedure TMailer.Connect(const AHost: String; APort: Integer;
   ASecurity: TMailerSecurity; AAuthenticate: Boolean;
   const AUsername, APassword: String);
begin
   SMTP := TSMTPSend.Create;
   if AAuthenticate then
   begin
     SMTP.UserName := AUsername;
     SMTP.Password := APassword;
   end;
   SMTP.TargetHost := AHost;
   SMTP.TargetPort := IntToStr(APort);
   SMTP.AutoTLS := (ASecurity = msSTARTTLS);
   SMTP.FullSSL := (ASecurity = msSSLTLS);
   SMTP.Timeout := 10000; // 10 seconds
   if not SMTP.Login then
     raise EMailer.CreateSMTP('SMTP.Login', SMTP);
   if AAuthenticate then
     if not SMTP.AuthDone then
       raise EMailer.Create(sMailerNotAuthenticated);
end;

================================================

Regards,
Denis

Brian wrote 15 lines
Does anybody have a working example of sending e-mail from a Lazarus program through their ISP's mail server (which requires SSL/TLS) that they'd be willing to share with me? I've been trying to follow Michael's writeup for using Synapse, I'm getting a timeout error from deep within the Synapse code, and I don't know whether it's something that I've screwed up or some kind of incompatibility with the mail server - my ISP, of course, will only tell me to use Outlook or similar. :( If I try to step through with the debugger, I get a socket error of 110. The version of Synapse I'm using is (I think) 40.1, at least it's the version downloaded via the online package manager. I'm using Lazarus 1.8.2 and FPC 3.0.4 as downloaded from SourceForge. Thanks.

Reply by email

Graeme Geldenhuys
to Brian: Does anybody have a working example of sending e-mail from a Lazarus program through…
Brian wrote
Does anybody have a working example of sending e-mail from a Lazarus program through their ISP's mail server (which requires SSL/TLS) that

I've been doing that for years, and have always used Indy components since my Delphi 4 days. Indy also has a ton of working examples, very simple to use components, and the support is fantastic (just like FPC and Lazarus). The extra good news is that there are tons of examples and solutions available with a quick internet search - even if those solutions are for Delphi, they apply exactly the same for FPC/Lazarus.

The latest Indy code can be found here:

https://svn.atozed.com:444/svn/Indy10/trunk

ps:
You don't have to install the Indy components into Lazarus, you can use them via code only without problems. That's what I do. Simply set your search paths, or compile the runtime lazarus packages and associate the indy package as a dependency of your project.

A internet search _will_ give you your answer, but if you really are stuck, I have working example code I can share. My programs can sent emails via Gmail, Yahoo, Office365 or any other ISP.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Alonso Cárdenas Márquez
to Brian: Does anybody have a working example of sending e-mail from a Lazarus program through…

2018-05-10 8:31 GMT-05:00 Brian via Lazarus :

Show quoted text 17 lines
Does anybody have a working example of sending e-mail from a Lazarus program through their ISP's mail server (which requires SSL/TLS) that they'd be willing to share with me? I've been trying to follow Michael's writeup for using Synapse, I'm getting a timeout error from deep within the Synapse code, and I don't know whether it's something that I've screwed up or some kind of incompatibility with the mail server - my ISP, of course, will only tell me to use Outlook or similar. :( If I try to step through with the debugger, I get a socket error of 110. The version of Synapse I'm using is (I think) 40.1, at least it's the version downloaded via the online package manager. I'm using Lazarus 1.8.2 and FPC 3.0.4 as downloaded from SourceForge. Thanks. --

Hi Brian

Try with the following:

https://github.com/silvioprog/brookframework/tree/master/plugins/xmailer

It is a great plugin for send email developed by Silvio. I use it to sending emails from different hosts with SSL/TLS. It uses synapse (Look at demo folder). Don't forget check if email ports are open for you by your ISP. You just need smtp ports (25, 587) to sending emails.

Greetings
ACM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180510/f2eb6afa/attachment.html>

Reply by email

Graeme Geldenhuys
brian wrote
I omitted to put in my original post that I'm running 64-bit Ubuntu Studio. All the Indy examples I've been able to find seem to require Windows DLLs to implement SSL/TLS.

It works just fine under Windows, Linux and FreeBSD too. I've testing them all. On Linux and Windows it uses the OpenSSL libraries - which normally comes standard with the system.

To save you some trouble, I've attached a fully working console demo. Edit the config.ini to match your details. Also edit the SMTP host name inside the program unit. Sending emails via Gmail requires a extra step
- you need to log into your Gmail with a Web Browser and under security settings, authenticate the "unknown device". When the console app gives an error on the first run, it will output URL you can use to get to that settings page (thanks Google).

The "IndySecureMailClient.pas" implements a wrapper class for Indy's SMTP and SSL handling making it super easy to use. The wrapper class in fact adds all Indy's abilities of encryption for convenience. Indy rocks!!!

I hope that helps.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp -------------- next part -------------- A non-text attachment was scrubbed... Name: indy_SecureEmail.7z Type: application/x-7z-compressed Size: 2983 bytes Desc: not available URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180512/49afa21e/attachment-0001.7z>

Reply by email

Brian
to Graeme Geldenhuys
Graeme Geldenhuys wrote 23 lines
On 2018-05-11 01:12, brian wrote: > I omitted to put in my original post that I'm running 64-bit Ubuntu > Studio. All the Indy examples I've been able to find seem to require > Windows DLLs to implement SSL/TLS. It works just fine under Windows, Linux and FreeBSD too. I've testing them all. On Linux and Windows it uses the OpenSSL libraries - which normally comes standard with the system. To save you some trouble, I've attached a fully working console demo. Edit the config.ini to match your details. Also edit the SMTP host name inside the program unit. Sending emails via Gmail requires a extra step - you need to log into your Gmail with a Web Browser and under security settings, authenticate the "unknown device". When the console app gives an error on the first run, it will output URL you can use to get to that settings page (thanks Google). The "IndySecureMailClient.pas" implements a wrapper class for Indy's SMTP and SSL handling making it super easy to use. The wrapper class in fact adds all Indy's abilities of encryption for convenience. Indy rocks!!! I hope that helps.

Thank you. I'll take a close look at it all over the weekend. I much prefer this sort of solution to trying to call one of the Linux 'mail from command line' utilities.

Brian.

Reply by email

Bo Berglund
to Graeme Geldenhuys: It works just fine under Windows, Linux and FreeBSD too. I've testing them all. On Linux…
Graeme Geldenhuys wrote
Indy rocks!!!

+1

And additionally the support available at the Indy forum is very good! https://www.atozed.com/forums/forumdisplay.php?fid=9

If you ask sensible questions you *will* get help there!

Note that the old atozed forum was taken down on technical reasons a while ago and the old posts there are not yet available for browsing. Apparently they are working on a way to restore the old database.

Bo Berglund Developer in Sweden

Reply by email

Graeme Geldenhuys
to Bo Berglund
Bo Berglund wrote
Note that the old atozed forum was taken down on technical reasons a while ago and the old posts there are not yet available for browsing. Apparently they are working on a way to restore the old database.

I've always connected to their NNTP newsgroup servers at:

news.atozed.com

Clearly that was not affected by the web forums. All old and new posts are still there - and available to be searched. Lots of useful information too.

Whenever I posted questions there, I got answers the same day or in 1 day. Very good support.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email