UDF SendMail for Firebird - Installation Instructions

First: copy files to right places:

(Download it from here)

Windows Environment:

a) copy file libwkSendMail.dll to UDF Folder, usually at
    C:\Program Files\Firebird\Firebird_1_5\UDF

b) the file wkSendMail.conf is located at the Firebird Bin folder, like
    C:\Program Files\Firebird\Firebird_1_5\bin

c) change to your settings, create file wkSendMail.conf if it not exists.

Linux Environment:

a) copy file libwkSendMail.so to "UDF Folder", see your installation, may be,  for example at  /opt/firebird/UDF   (case sensitive!)

b) change owner to the same user of Firebird process, usually firebird too:

   chown firebird:firebird libwkSendMail.so

c) set rights for 644

   chmod 644 libwkSendMail.so

d) the file wkSendMail.conf is located at the Linux ETC folder, like
    /etc/wkSendMail.conf

e) change to your settings, create file wkSendMail.conf if it not exists, and
   give same permissions and owner to like A and B steps.
  
f) create the file wkSendMail.log on /var/log, and give same rights like A and
   B steps

    touch /var/log/wkSendMail.log
    chown firebird:firebird libwkSendMail.so
    chmod 644 libwkSendMail.so

Register UDF in Firebird

Create a entry point on each database you want to use de SendMail function. To create the function, run the script below:

DECLARE EXTERNAL FUNCTION SENDMAIL
    CSTRING(255),
    CSTRING(255),
    CSTRING(32767),
    CSTRING(32767)
RETURNS INTEGER BY VALUE
ENTRY_POINT 'SendMail' MODULE_NAME 'libwkSendMail';

License:

Since 2017 you now can send up to 10 messages without license information. You can restart Firebird to get 10 more. Of course, you can't do that in production servers, so a license is required for that.

If want to register please access http://www.suportedireto.com.br/udf-register.html and Click on the Button  "Buy Now".

Follow the PayPal instructions and after approved, you will receive your license key on your e-mail automatically. Please check your Spam folder.

SMTP settings and License on wkSendMail.conf

Latest WINDOWS (DLL) version is compatible with Google / Gmail SSL account, using port 465. You will need to create an Application-Specific password for that, please see http://support.google.com/accounts/bin/answer.py?answer=185833

In most cases, the file wkSendMail.conf is auto generated at first run of the function. If it not exists, see at the especific OS topic above how to create it.

Sample wkSendMail.conf:

  [license]
  username=your@email.com
  key=12345-67890123-456

  [wkSendMail]
  smtp_host=127.0.0.1
  smtp_port=25
  smtp_timeout=5000
  log_level=0
  smtp_username=
  smtp_password_b64=
  smtp_password=
  bcc=
  _________________________

[license]

Provide your license information, read License topic above to see how to get it.
username: e-mail you used to register. This e-mail will go on the MailAgent
          header of each message. (case sensitive!)
key:      license key you received by email

[wkSendMail]
smtp_host:     your smtp host or IP
smtp_port:     your smtp port, usually 25 or 587
smtp_timeout:  maximum time to wait for connection (in miliseconds, 5000 default)
log_level:     type of detail of the Log,
               0 - errors only (default)
               5 - lot of details.
smtp_username: if you need smtp authentication, provide username and password.

smtp_password: the password for authentication, in plain text. Note: Gmail Users must create an Application-Specific password, see notes above.

smtp_password_b64: this property takes priority over smtp_password; it is a simple base64 version of the password; if you specify this field, there is no need to provide plain password. Generate your Base 64 password at http://www.motobit.com/util/base64-decoder-encoder.asp. Note: Gmail Users must create an Application-Specific password, see notes above.

bcc:           send a copy of each message to an account.

Log file

There is a log file available, if you are having troubles, take a look on the
file wkSendMail.log, see you SO topic.

Function Return codes:

1    Success queued on SMTP server.
-1    Can't create or access wkSendMail.conf file
-2    Error sending message (wrong SMTP authentication, see Log description)
-3    License error - take a look on the email you received.

How to test and use:

    select sendmail (
	'udf_firebird@my.cool-server.org',
	'me@some-place.com',
	'A Subject',
        'A body text<br>Another line') as result
    from 
	rdb$database;


Trigger Example

SET SQL DIALECT 3;

SET NAMES NONE;
SET TERM ^ ;

CREATE TRIGGER BANCO_AI0 FOR BANCO
ACTIVE AFTER INSERT POSITION 0
AS
    declare variable i integer;
begin
    SELECT sendmail (
	'udf_firebird@my.cool-server.org',
	'me@some-place.com',
'An after insert event occurred in table tbl_important', 'This is an automated message<br>Customer ' || new.customer_name || ' created.') FROM rdb$database INTO i; end ^ SET TERM ; ^