sendmail
Syntax
call = sendmail(from-address, to-address, cc-address, subject, message-body, file-attachments, format)
Arguments
from-address, to-address,
cc-address, subject,
message-body,
file-attachments: text
format: 1 or 0
call: integer
Meaning
Sends an e-mail to the specified recipient(s). From-address is a mandatory e-mail address of the sender; to-address is a mandatory e-mail address of the recipient, cc-address is an optional e-mail address of a secondary recipient; subject is optional; message-body is the actual message; file-attachments is an optional list of filenames. To-address and file-attachments may be repeated with semi-colon separators (this doesn't work for the cc-address). The format argument is optional: 1 means that the message body must be interpreted as an HTML page (see the TRANSFORM function), while 0 means that the message body is plain text; plain text is the default setting if the format argument is left out (so that the sendmail statement has only six arguments).
The function operates either with SMTP or MAPI (Microsoft’s messaging application programming interface), although the format 1 only works with SMTP. If a so-called smarthost environment variable has been set, SMTP will be used, otherwise MAPI will be attempted, but with MAPI the sender address needs to be the sender address of the currently logged-in user.
Note that you always need to provide at least six arguments (and seven at most); only for said optional arguments among the first six you may enter an empty value. You do this with two single quotes ''. Literal e-mail addresses and text need to be enclosed by single quotes too. The last argument (format) and the comma in front of it, may be left out altogether.
Call is zero if sendmail was executed succesfully. Each other value is an error code. If any of the mandatory arguments is missing, an error code is generated and there won't be a different attempt to send the e-mail. If the file-attachments argument is provided, but the file cannot be found, then the e-mail won't be sent and Call will be 11.
A special option is to use the contents from a text file as the message body, without having to specify the name of this file: a sendmail command with an empty message-body argument (two single quotes) will automatically use the contents from a text file if that text file has been generated in the current adapl. Typically you would code this as follows:
pdest 'myfilename.txt' file
print 1, 0, 'This is the first line of the message body'
output
print 1, 0, '...'
output
print 1, 0, 'This is the last line of the message body'
output
sendmail(sender, receiver, '', subject, '', '')
However, this functionality is not self-evident to anyone reading your code, so it would be good to document it in the code. Also note that if you are not going to use the text file for anything else, there's a better way to build up the text for a message body: just declare a long text variable (like text mailbody[0]), add text strings and carriage returns plus line feeds as shown below and enter the mailbody variable as the fifth argument in your sendmail command.
mailbody = 'This is the first line of the message body' + CHR$(13) + CHR$(10) + ~
'...' + CHR$(13) + CHR$(10) + ~
'This is the last line of the message body'
sendmail(sender, receiver, '', subject, mailbody, '')
Setting ADLIB_SMARTHOST
For sending e-mail through SMTP, the variable ADLIB_SMARTHOST must be set to the name of the mail server which Collections should use. With ADAPL (also for stand-alone adapls executed via RunAdapl.exe), this environmental variable can be set as follows: enter the line setvar('ADLIB_SMARTHOST', ‘<name-of-my-smtp-server>’) in the ADAPL file from which e-mails are sent (and replace <name-of-my-smtp-server> by the actual name of your smtp server), preferably at the start of the file or at least before an e-mail is sent. You can only send out e-mails from within the adapl with this code!
Example
setvar('ADLIB_SMARTHOST', 'mailserver.ourmuseum.com')