On Mon, 10 May 2021 10:08:53 +0200 (CEST), Michael Van Canneyt via fpc-pascal
<fpc-pascal@lists.freepascal.org> wrote:

>
>
>On Mon, 10 May 2021, Bo Berglund via fpc-pascal wrote:
>
>>
>> I have now installed  Synapse 40.1 in LKazarus 2.0.12 with Fpc 3.2.0
>>
>>> I use it myself in a headless FPC-created server running on linux, since 
>>> many many
>>> years, and use it in a Delphi-created server also running on linux, so I'm 
>>> very
>>> confident it works as described :-)
>>
>> I have also read your document (pdf):
>> http://www.freepascal.org/~michael/articles/lazmail/lazmail-en.pdf
>>
>> But it seems like I still need an example showing how to enable the SSL (port
>> 465) *without* modifying Synapse itself...
>> This is not mentioned there (also not mentioned are the uses entries for the
>> example code to work...).
>>
>> I found this thread in the forum stating that it is written to help for this
>> problem:
>> https://forum.lazarus.freepascal.org/index.php?topic=27222.msg168067#msg168067
>>
>> But the solution here seems to *modify* Synapse package code itself, which I
>> think is a very bad idea, especially for code that needs to build on "out of 
>> the
>> box" Lazarus installations only specifying which packages to install.
>>
>> It is very strange to me.
>> So a working SSL SMTP sending example (with file attachments)would help a lot
>> because my mail server demands such validation to allow sending.
>
>You don't need to change Synapse ?
>
>My setup is basically:
>
>     FSMTP.TargetHost:=MailCfg.HostName;
>     FSMTP.TargetPort:=IntToStr(MailCfg.Port);
>     FSMTP.AutoTLS:=MailCfg.UseTLS;
>     FSMTP.FullSSL:=MailCfg.FullSSL;
>     FSMTP.Username:=MailCfg.SMTPUserName;
>     FSMTP.Password:=MailCfg.SMTPPassword;
>
>You need these properties:
>
>     {:If is set to true, then upgrade to SSL/TLS mode if remote server 
> support it.}
>     property AutoTLS: Boolean read FAutoTLS Write FAutoTLS;
>     {:SSL/TLS mode is used from first contact to server. Servers with full
>      SSL/TLS mode usualy using non-standard TCP port!}
>     property FullSSL: Boolean read FFullSSL Write FFullSSL;
>
>That's it. From your story, it seems you just need to set
>   FSMTP.TargetPort:=465;
>   FSMTP.FullSSL:=True;
>

Not so simple when you read scores of Internet pages on the subject...
Maybe I am reading an old version (from 2012) of your document lazmail-en.pdf?
The example I have found for the attachments handling uses a call to SendToRaw
inside Synapse where I cannot get at the SSL handling (without changing the
Synapse package code).

Here is where I am at now trying to make a function to send email with a
plaintext message plus at least one file attachment.
I started with the simple example from the wiki page and next I need to expand
it with code from the pdf regarding the attachments (once tyhe plain text
function works):

(*******************************************************************************
* This function is based on the examples in:
* https://wiki.freepascal.org/Synapse#Sending_email 
* and
* https://www.freepascal.org/~michael/articles/lazmail/lazmail-en.pdf
********************************************************************************)
function SendSSLMail(const Subject, MailTo, MailFrom: string; Body, Attachments:
TStrings): boolean;
var
  SMTP: TSMTPSend;
begin
  SMTP:=TSMTPSend.Create;
  try
    SMTP.UserName := FSmtpUser;
    SMTP.Password := FSmtpPasswd;
    SMTP.TargetHost:= FSmtpHost;
    SMTP.TargetPort := FSmtpPort; //465
    SMTP.AutoTLS := true;
    SMTP.FullSSL:=true;

    if SMTP.Login then
    begin
      //What is happening here? 3 SMTP calls in a boolean expression?
      Result:=SMTP.MailFrom(MailFrom, Length(Body.Text)) and
         SMTP.MailTo(MailTo) and
         SMTP.MailData(Body);
      SMTP.Logout;
    end;

  finally
    SMTP.Free;
  end;
end;

Where is the actual sending of the email happening?
And how do I add the attachments?


-- 
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to