Code Monkey home page Code Monkey logo

mailer4delphi's Introduction

Mailer For Delphi

Mailing tool aimed for simplicity, for sending e-mails of any complexity in Delphi. This includes e-mails with plain text and/or html content, embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL. The Mailer4Delphi provides a driver-independent framework to build mail and messaging applications.

The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some mainstream client applications such as MS Outlook or Mozilla Thunderbird.

Mailer Adapters Drivers

The Mailer4Delphi is available for the following drivers:

  • Indy
  • MAPI
  • Synapse
  • Outlook

You can use the driver that suits you best.

Using Mailer4Delphi

Using this API will is very simple, you simply add the Search Path of your IDE or your project the following directories:

  • Mailer4Delphi\src

Of course, you must add the path the units of the chosen driver.

Example of use:

uses
  Mailer4D, 
  Mailer4D.Driver.Indy;

var
  mailer: IMailer;
begin
  // Here you can create from any driver.
  mailer := TIndyMailer.Create;
  mailer.Host('smtp.example.com')
	.Port(587)
	.Username('[email protected]')
	.Password('password')
	.From('Test', '[email protected]')
	.ToRecipient('[email protected]')
	.CcRecipient('[email protected]')
	.BccRecipient('[email protected]')
	.Attachment('C:\File.txt')
	.Subject('Subject Test')
	.Message('Message Test')
	.Send;
end;

mailer4delphi's People

Contributors

dsonda avatar ezequieljuliano avatar laffsj avatar oneideluizschneider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailer4delphi's Issues

Definição de CharSet

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

Attachment sending issue with the Synapse driver (Indy's ok)

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:
mailer4delphi_SynapseImageAttachmentIssue

Problema ao executar em debug.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.