Parabéns pelo trabalho Ezequiel
Como sugestão fica a definição de CharSet, importante na definição do e-mail para envio pelo Indy
Segue exemplo implementação, inclusive em anexo:
unit Mailer4D;
interface
uses
System.Classes,
System.SysUtils;
type
EMailerException = class(Exception);
IMailer = interface
['{E2741CF9-C79F-4396-8D80-068BE8950AA4}']
function Host(const value: string): IMailer;
function Port(const value: Integer): IMailer;
function Username(const value: string): IMailer;
function Password(const value: string): IMailer;
function UsingSSL(const value: Boolean = True): IMailer;
function UsingTLS(const value: Boolean = True): IMailer;
function AuthenticationRequired(const value: Boolean = True): IMailer;
function CharSet(const value: string): IMailer;
function From(const name, address: string): IMailer;
function ReplyTo(const name, address: string): IMailer;
function ToRecipient(const address: string): IMailer;
function CcRecipient(const address: string): IMailer;
function BccRecipient(const address: string): IMailer;
function AskForConfirmation(const value: Boolean = True): IMailer;
function Attachment(const fileName: string): IMailer;
function Subject(const value: string): IMailer;
function Message(const value: string): IMailer; overload;
function Message(const value: TStringList): IMailer; overload;
function UsingHTML(const value: Boolean = True): IMailer;
procedure Send;
end;
implementation
end.
Na unit Mailer4D.Indy.Impl
procedure TIndyMailer.AddBody(const msg: TIdMessage);
var
ContentType: string;
body: TIdText;
begin
body := TIdText.Create(msg.MessageParts);
body.Body.Text := GetMessage.Text;
if IsWithHTML then
ContentType := 'text/html'
else
ContentType := 'text/plain';
if GetCharSet <> '' then
ContentType := ContentType + '; charset=' + GetCharSet;
body.ContentType := ContentType;
end;
procedure TIndyMailer.DoSend;
var
smtp: TIdSMTP;
msg: TIdMessage;
begin
inherited;
smtp := TIdSMTP.Create(nil);
try
try
ConfigureSmtp(smtp);
msg := TIdMessage.Create(nil);
try
msg.Date := Now;
msg.Subject := GetSubject;
msg.ContentType := 'multipart/mixed';
msg.CharSet := GetCharSet;
[...]
Na unit Mailer4D.Base.Impl;
TBaseMailer = class abstract(TInterfacedObject, IMailer)
private
fHost: string;
fPort: Integer;
fUsername: string;
fPassword: string;
fSSL: Boolean;
fTLS: Boolean;
fAuthentication: Boolean;
fCharSet: string;
[..]
protected
function GetCharSet: string;
[..]
public
function CharSet(const value: string): IMailer;
[..]
function TBaseMailer.CharSet(const value: string): IMailer;
begin
fCharSet := value;
Result := Self;
end;
constructor TBaseMailer.Create;
begin
inherited Create;
fHost := EmptyStr;
fPort := 0;
fUsername := EmptyStr;
fPassword := EmptyStr;
fSSL := False;
fTLS := False;
fAuthentication := False;
fCharSet := 'utf-8';
[...]
function TBaseMailer.GetCharSet: string;
begin
Result := fCharSet;
end;
Mailer4D.Base.Impl.txt
Mailer4D.Indy.Impl.txt
Mailer4D.txt