ADUG membership software applications uses Indy to send email notification to members. The actual email code has been modified over the years with help from various members. There is now an outstanding request to enable HTML in emails. This should not be difficult but I cannot immediately see how the HTML content is flagged in the email header. Eg from a Forums HTML post
X-Virus-Scanned: Debian amavis at b2.tigertech.net
Received: from forums.adug.org.au (ec2-54-206-238-124.ap-southeast-2.compute.amazonaws.com [54.206.238.124])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
(No client certificate requested)
by mailb2.tigertech.net (Postfix) with ESMTPSA id 4Y2KhL3q9Pz1nscm
for <roger@innovasolutions.com.au>; Mon, 2 Dec 2024 15:27:46 -0800 (PST)
Date: Mon, 02 Dec 2024 23:27:46 +0000
From: ADUG Forums <noreply@adug.org.au>
Reply-To: ADUG Forums <noreply@adug.org.au>
To: roger@innovasolutions.com.au
Message-ID: <c863defa-30dd-4ffb-a37e-8a4220cd0422@forums.adug.org.au>
Subject: [ADUG Forums] Summary
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_674e4270afa65_2e2a0f3d3b026272d5";
charset=UTF-8
Content-Transfer-Encoding: 7bit
List-Unsubscribe: <https://forums.adug.org.au/email/unsubscribe/00f57141caefb9b5c4fdd1aaf06734c3b64aaea01f23503df88035994446cacf>
X-Discourse-Post-Ids: 228554
X-Discourse-Topic-Ids: 60535
X-Auto-Response-Suppress: All
Auto-Submitted: auto-generated
----==_mimepart_674e4270afa65_2e2a0f3d3b026272d5
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
A brief summary of [ADUG Forums][1] since 2024-12-01 23:02:37 UTC
1 New Topics
--------------------------------------------------------------------------------
### Popular Topics
The current Email Sender Code is
function TDbConfigurationDataObject.EmailSend(out AError: AnsiString;
const Subject: string; const MsgBody: string;
const EmailToAddress: AnsiString; const EmailSenderAddress: AnsiString;
const EmailReturnAddress: AnsiString; AttachFileNames: array of AnsiString;
const EmailCopyAddresses: AnsiString;
const EmailBCCAddresses: AnsiString): Boolean;
var
Smtp: TIdSMTP;
MailMsg: TIdMessage;
MainMessage: TIdText;
i: Integer;
// Added to Enable SSL for gmail
// uses IdUserPassProvider,IdSASLLogin,IdSSLOpenSSL,IdExplicitTLSClientServerBase
PasswordProvider: TIdUserPassProvider;
SaslLogin: TIdSaslLogin;
SslIoHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
AError := '';
if GBLSMTPServerHostAddress = '' then
raise Exception.Create
('You Need to set up the GBLSMTPServerHostAddress Variable');
Result := false;
if gblHoldEmailIfDebug then
begin
Result := True;
Exit;
end;
// Added to Enable SSL for gmail
PasswordProvider := nil;
SaslLogin := nil;
SslIoHandler := nil;
try
Smtp := TIdSMTP.Create(nil);
MailMsg := TIdMessage.Create(nil);
try
Smtp.Host := GBLSMTPServerHostAddress;
Smtp.MailAgent := ccMailAgent;
Smtp.Port := GblSMTPPort;
if GBLSMTPServerPasswordEncrpted <> '' then
if GBLSMTPServerSenderAccount <> '' then
begin
Smtp.Username := GBLSMTPServerSenderAccount;
Smtp.Password := TCgiAccessObj.DecryptEmailPassword
(GBLSMTPServerPasswordEncrpted);
// Added to Enable SSL for gmail
if GblSMTPUseSSL then
begin
PasswordProvider := TIdUserPassProvider.Create(nil);
// neither is this
SaslLogin := TIdSaslLogin.Create(nil); // or this
SslIoHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
SslIoHandler.SSLOptions.Method := sslvTLSv1_2;
SslIoHandler.SSLOptions.SSLVersions := [sslvTLSv1_2];
SslIoHandler.SSLOptions.VerifyMode := [];
SslIoHandler.SSLOptions.VerifyDepth := 2;
Smtp.IoHandler := SslIoHandler;
Smtp.UseTLS := utUseImplicitTLS;
Smtp.AuthType := satDefault;
end;
end;
MailMsg.Subject := Subject;
MailMsg.Recipients.EMailAddresses := EmailToAddress;
MailMsg.From.Text := EmailSenderAddress;
if EmailReturnAddress <> '' then
MailMsg.ReplyTo.EMailAddresses := EmailReturnAddress
else
MailMsg.ReplyTo.EMailAddresses := EmailSenderAddress;
MailMsg.CCList.EMailAddresses := EmailCopyAddresses;
MailMsg.BccList.EMailAddresses := EmailBCCAddresses;
MainMessage := TIdText.Create(MailMsg.MessageParts, nil);
MainMessage.Body.Text := MsgBody;
if CompressedUnicode(MsgBody) = '' then
begin
MailMsg.ContentTransferEncoding := '8bit';
MainMessage.ContentType := 'text/plain; charset=UTF-8';
end;
// CharSet := 'UTF-8';
// https://stackoverflow.com/questions/9844250/not-able-to-send-utf-8-email-using-delphi-indy
for i := 0 to high(AttachFileNames) do
begin
if (AttachFileNames[i] <> '') and FileExists(AttachFileNames[i]) then
TIdAttachmentFile.Create(MailMsg.MessageParts, AttachFileNames[i]);
end;
Smtp.Connect;
try
Smtp.Send(MailMsg);
finally
Smtp.Disconnect;
end;
Result := True;
except
on E: Exception do
try
AError := E.Message;
LogALine(FormatDateTime('dd mmmm yyyy hh:nn', Now));
LogALine('Email Error: Server:' + GBLSMTPServerHostAddress + ':' +
E.Message);
LogALine('Subject::' + MailMsg.Subject + ' To:' +
MailMsg.Recipients.EMailAddresses);
LogALine('MailMsg.ReplyTo.EMailAddresses =' +
MailMsg.ReplyTo.EMailAddresses);
LogALine('MailMsg.From.Text =' + MailMsg.From.Text);
Result := false;
if Assigned(FEmergengyEmailFunction) then
begin
FEmergengyEmailFunction('Problem At ADUG Email',
'Subject::' + MailMsg.Subject + ' To:' +
MailMsg.Recipients.EMailAddresses, EmailManagementMessages,
EmailSenderAddress, EmailReturnAddress, []);
Result := FEmergengyEmailFunction(Subject, MsgBody, EmailToAddress,
EmailSenderAddress, EmailReturnAddress, AttachFileNames,
EmailCopyAddresses, EmailBCCAddresses);
end;
except
end;
end;
try
MailMsg.Free;
except
end;
Smtp.Free;
// Added to Enable SSL for gmail
PasswordProvider.Free;
SaslLogin.Free;
SslIoHandler.Free;
except
on E: Exception do
Result := false;
end;
end;
I think the bit of code which needs modification is
MailMsg.Subject := Subject;
MailMsg.Recipients.EMailAddresses := EmailToAddress;
MailMsg.From.Text := EmailSenderAddress;
if EmailReturnAddress <> '' then
MailMsg.ReplyTo.EMailAddresses := EmailReturnAddress
else
MailMsg.ReplyTo.EMailAddresses := EmailSenderAddress;
MailMsg.CCList.EMailAddresses := EmailCopyAddresses;
MailMsg.BccList.EMailAddresses := EmailBCCAddresses;
MainMessage := TIdText.Create(MailMsg.MessageParts, nil);
MainMessage.Body.Text := MsgBody;
if CompressedUnicode(MsgBody) = '' then
begin
MailMsg.ContentTransferEncoding := '8bit';
MainMessage.ContentType := 'text/plain; charset=UTF-8';
end;
// CharSet := 'UTF-8';
// https://stackoverflow.com/questions/9844250/not-able-to-send-utf-8-email-using-delphi-indy
You are right I could go and research the email standards but this is ADUG code and I am hoping some ADUG community member is already across the issue.