Sending Email

Send email message

Free Pascal users have some options when sending email. Some library such as Indy has TIdSMTP which connect directly to SMTP server. As alternative, Fano Framework offers a way to send email by using sendmail binary.

IMailer interface

To abstract away mail sender implementation, IMailer interface is provided. It is a contract for any class having capability to send email.

Sending email with sendmail

Current implementation of IMailer interface only supports sending email using sendmail binary, from ssmtp library thorough class TSendmailMailer. To use it, register its factory class with container.

container.add('mailer', TSendmailMailerFactory.create());
var amailer : IMailer;
amailer := container['mailer'] as IMailer;
amailer.recipient := '';
amailer.sender := '';
amailer.subject := 'Hello';
amailer.body := 'Hello world';

Setting up ssmtp library

To install ssmtp in Debian-based distribution,

$ sudo apt install ssmtp

or Fedora-based,

$ sudo yum install ssmtp

Edit /etc/ssmtp/ssmtp.conf and add following lines,

Replace mailhub, AuthUser, AuthPass with your own value. If you do not setup dedicated SMTP server, you can use external SMTP server such as gmail or mailtrap, or MailHog. Both mailtrap and MailHog is fake SMTP server which helps sending test email without fear of becoming email spammer during development.

Explore more