ezequieljuliano / mailer4delphi Goto Github PK
View Code? Open in Web Editor NEWFor sending e-mails of any complexity in Delphi
License: Apache License 2.0
For sending e-mails of any complexity in Delphi
License: Apache License 2.0
First, thanks for this wonderful mailer class.
I'd like to report an issue - it might be related to Synapse itself other than mailer4delphi, because the same issue exists with pain Synapse (use smtpsend.pas directly).
however, I still want to post the issue here hoping someone might can help.
The issue is that after after the email reached the receiver's mailbox (gmail in this case), the email client shows there is an attachment (a PNG image in this case), but the file is not valid, but with the Indy driver it's OK, the issue only exists with the Synapse driver.
The email's sent from Amazon SES' SMTP to a Gmail mailbox.
Any thought as to how to fix it? I want to use Synapse if possible coz in the other parts of my program I use Synapse. See attached screenshot below:
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;
Ezequiel gostaria de relatar um problema que tive.
Ao executar testes com o mapi, em modo debug e com o outlook aberto, ele enviou direto e não me mostrou a tela do email, já com o outlook fechado, ele carrega a tela par eu preencher os dados. Em release esta normal.
Gostaria de ver com você também sobre o anexo se seria possível deixar somente o nome do arquivo e não o caminho com o nome como esta mostrando.
Obrigado.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.