#1 2023-01-19 17:35:43

tbo
Member
Registered: 2015-04-20
Posts: 224

SendEMail function

Would it be possible to add a SendEMail function with these parameters.

function SendEMail(const pmcServer: TSMTPConnection; const pmcFrom, pmcToCSV, pmcRawEMail: RawUtf8; pmIsTLS: Boolean = False): Boolean;

Background: I create the EMail document (header + body) using the Indy classes TIdMessage and TIdMessageBuilderHTML/Plain. This is very simple as follows:

idMessage := TIdMessage.Create(Nil);
try
  idMessage.Subject := ...;
  idMessage.From.Address := ...;
  idMessage.Recipients.Add.Address := ...;
  idMessageBuilder := TIdMessageBuilderHTML.Create;
  try
    idMessageBuilder.Html.Text := AnyTextFileToString('EMail.html', True);
    idMessageBuilder.FillMessage(idMessage);
  finally
    idMessageBuilder.Free;
  end;

  idMessage.SaveToStream(rawStream);
  SendEMail(connection, StringToUtf8(idMessage.From.Address), StringToUtf8(idMessage.Recipients.EMailAddresses), rawStream.DataString, False);

So far I still use my own SendEMail function, derived from mORMot SendEMail function.

With best regards
Thomas

Offline

#2 2023-01-20 09:11:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,504
Website

Re: SendEMail function

You will still need to set the proper content-type, since the body is not just some text, but a multi-part content.

It could be possible now with
https://github.com/synopse/mORMot2/commit/61413640
if you set TextCharSet = '' and specify the content-type in the headers.

Offline

#3 2023-01-20 16:14:25

tbo
Member
Registered: 2015-04-20
Posts: 224

Re: SendEMail function

ab wrote:

You will still need to set the proper content-type, since the body is not just some text, but a multi-part content.

Thanks for your efforts. Yes, and Indy MessageBuilder does it perfectly. It creates the complete EMail document with header and body and considers every possibility. Even attachments can be added just like that.

idMessageBuilder.Attachments.Add('C:\InfoData.pdf');

Everything is encoded correctly. For me, only the sending mechanism from mORMot is interesting. I extracted this part from the SendEMail function and tested/used it with SMTP/SMTPS servers and EMail client programs. It works perfectly. If you want to know what Indy MessageBuilder does, you can save the result to a file.

idMessage.SaveToFile(MakePath([Executable.ProgramFilePath, 'EMail.txt']));

I have the perfect solution working for me. But when I suggest mORMot as a solution to Indy users who have a problem with SSL/TLS, they find the existing too complicated. My suggestion is the best of both worlds.

With best regards
Thomas

Last edited by tbo (2023-01-20 16:47:14)

Offline

Board footer

Powered by FluxBB