Return to the technote repository How to send
an Email ?
 

Introduction

You can send emails within Magic in two ways : without user intervention (by using a DLL, a command line program or OLE Automation) or with user intervention (invoke the email application, and specify the recipient, the subject, ...).

Magic eDeveloper V9 now supports POP3, SMTP and IMAP protocols to read and send email, implemented as a set of nice integrated functions.

It is a good practice to purpose several ways to send an email in your application, as the best solution often depends on user architecture.

MAPI, Simple MAPI or CMC

This mailer tools use the installed mail package to send an email. If simple MAPI is provided with most mail applications, MAPI (that provides a larger set of functions) is mostly provided by Exchange or Outlook. MAPI is Windows specific, but CMC can be implemented on several systems (Unix, Windows), although CMC is no more implemented in Outlook.

By MAPI design, you can't use MAPI from a service.

Outlook and Outlook Express are often used by computer viruses to propagate. Microsoft has put several limits on recent versions, so those versions are no more really compatible simple MAPI (limits on attachments, dialog boxes for user confirmation, ...). Take this in consideration if you choose this way to send mails.

The advantages of MAPI are

  • As it uses on the installed mail package, you don't have to store connection informations (smtp or pop3 server, login and password).
  • The messages are keep in the "Sent" message folder.

The disadvantages of MAPI are

  • It may not work depending on the mail package or the version of the mail package.
  • Slower than a stand-alone tool.

MAPI is the standard method to send an email in Windows, so it's used in several solutions.

  • MAILGET.DLL implements Simple MAPI. It supports TO: CC: and BCC: recipients, several attachments (freeware, Magic V7 or upper).
  • hfmapi.dll implements Simple MAPI to send an email (freeware, Magic V7 or upper).
  • sendmail.dll use Simple MAPI to send simple emails (one recipient, one attachment), sources are provided (freeware, Magic V8.2 or upper).
  • mgmapiml (mirror) is an upgraded sendmail.dll with sources. (freeware, Magic 7 or upper).
  • maillink (mirror), an unsupported freeware from MSE implements CMC under Windows and provide both sending and reading email (Magic V7 or upper). Note than CMC is no more implemented in Outlook.
  • Synopsis Systems Ltd sells a complete (sending and receiving) MAPI client as a DLL (Magic V7 or upper) and as an command line tool (All Magic versions on Windows 9#/NT through the Exit operation).

SMTP

This protocol is the standard internet mail protocol to send emails, all ISP provides it and most Mail Servers have an option to accept it (including Exchange Server). As this tools does not use the installed mail package, they are quicker and self-contained, but require more configuration (smtp server address, login, password).

  • Blat is a well known command line tool to send email. A DLL version now exists, an interface to this DLL is included in MAILGET.DLL (freeware, all Magic versions on Win9#/NT).
  • GetMail for Windows is a command line tool to retrieve emails on a POP3 server (shareware, all Magic versions on Win9#/NT).
  • hfmail.dll also lets you command dial-up networking (RAS), that can be useful with other packages as well (freeware, Magic V7 or upper).
  • Postie is a commercial command line solution to send and retrieve email ; it supports sending HTML body.
  • Magic 9 eDeveloper natively supports SMTP and POP3 protocols.

VIM (Lotus Notes)

  • notes.dll is a MSE freeware that lets you send and receive Lotus Notes emails (Freeware, Magic V7 or upper). It seems that Notes 5 is not supported, but MAPI is supported in the version. If you receive a "failed to load" error message when trying this solution, add in the PATH (autoexec.bat) the path of the Lotus application folder.
  • Sendmail is a freeware email command line tool for Lotus, using a now unsupported HiTest C API.

OLE Automation

For Magic 8.20 or upper, OLE automation commands depends on the email package.

If you can download Email from Magic from magicu-l shared folder, that uses OLE Automation to Outlook.

Mems Software sells a Magic DLL for Magic V7 or upper MagicToOutlook (mgoutlk.dll) that interfaces with Outlook through OLE.

SQL gateway

Microsoft SQL Server or MSDE

The KBase article Q263556 explains how to send mail from SQL. (Also look at KB 321183, KB 311231, KB 315886)

Invoking Email Package

Mailto: Protocol

You can use the exit Magic operation : mailto:address[,address]?subject=subject line&cc=address[,address]&bcc=address[,address]&body=message text&attachment='one file'.

Be aware that the whole command (including body text) must fit into the command line system limit (under 500 bytes under Windows 95).

The first separator is ?, following are &. You must use hexadecimal characters for special characters in variables, the following signs are used to represent commonly used characters:

Space ( ) %20
Comma (,) %2C
Question Mark (?) %3F
Period (.) %2E
Exclamation Point (!) %21
Colon (:) %3A
Semicolon (;) %3B

You can use 'hotfudge.mailto' or 'mailget.mailto' that deals with the conversion, if you want to do things yourself, be aware that Magic will alter the string, as '%' are interpreted as logical names, so you have to create a batch file (.bat) and launch this batch program through the 'exit' operation.

All mail packages does not support all the switches, although address and subject are commons, and attachment is quite rare. The RFC 2368 describes this protocol.

The user still have to use the send button.

Attachments

To send reports via attachment, you have to make this reports in a format that the recipient can read :

  • HTML : easier in V8, it can also be done with V7. The drawback is that you have to redesign existing reports, and that you don't have extended control (page break for instance is difficult).
  • RTF : you could also do an RTF file (wordpad, word, word viewer and most word processors can read it), through Output Merge.
  • PDF is the choice solution : reader is widely available (Acrobat Reader), it's a good solution for C/S and Web development. A PDF creator is simply a printer driver that produce a PDF file instead of printing. Existing reports (including bitmaps) are used, you just have to send the report to a file and use a particular printer. All about PDF at PDFzone or Planet PDF.

    You can generate PDF from several tools, look at PDF Software Review at magicu-l. It is harder but cheaper to use GhostScript (first PS then PS to PDF), look at MagicPDF.zip.

Another solution is to use a report generator or to produce a report in an intermediary format that can generate PDF :

  • EscorteR can generate either HTML, RTF or PDF, you make call to a Magic DLL to generate the report (freeware, MAgic V7 and upper).
  • The TeX User Group provide a tool to generate PDF. TeX is Donald E. Knuth famous text formatter.
  • ...