SendMail

E-mail
Aptilis 1

SendMail(To, From, Subject, Message[, ReplyTo])

This function allows you to send e-mail messages.
In order for it to work, all you need is to put a little text file in the default directory aptilis runs in.
Usually, that's the directory where you've installed aptilis. However in some cases, for instance when using aptilis for web scripts, the web server might put you in another directory. To find out in which directory you are, just use a simple script such as:

sub main

print("Content-type: text/plain\n\n")
print("the default directory is: ", GetCurrentDirectory() $)

end sub
and then call your script, saved as 'defdir.e.txt' from your web browser:
http://your.server.whatever/cgi-bin/aptilis.exe?file=C:\aptilis_programs\defdir.e.txt
Of course, you will need to adapt the URL above to your specific set-up.

There are two ways to configure the way aptilis sends e-mails:
Doing it once and for all in the file aptilis.mail which is going to be read the first time you use sendMail. But if you are on a foreign server, you will not be able to edit that file. The SMTP server used by default by your provider might not allow you to send e-mails if it does not know the 'from' address you gave the sendmail command. By setting the SMTP server programmatically with the setSMTPserver command.
The text file, which must be called aptilis.mail is composed of one line that looks like this:
SMTPSever,domain
For example, if your e-mail address is joe@provider.com your aptilis.mail should look something like:
mail.provider.com,provider.com
Note that the SMTPServer part is the most important one.
An IP number is also acceptable.
If in doubt, call your internet service provider as they should know!
See the setSMTPserver command. By specifying a mail server that knows you (or the address you use as 'from'), everything should be working perfectly.
Unfortunately some ISPs (Internet Service Providers) still won't allow you to use their SMTP server if you're not connecting from one of their dial-up accounts... The solution to that is to use one of the free e-mail providers out there who, when they offer SMTP services (So that you can use Eudora for example) are less fussy about where you're coming from.
Here is how you can find out the smtp server you use:
(Let's assume you are using Eudora 3.0, if you're not, the procedure should be similar anyway)
Click 'Tools'
Select 'Options...'
Select 'Hosts'
The SMTP server you're connecting to should be in there.

Of course, your computer needs to be connected to the Internet (or an intranet) if you want to be able to use this feature. If you're using a dial-up connection, make sure you connect before using this feature.

If you still can't use the required 'from' address, the optional ReplyTo parameter can help you go round that. Check the notes at the bottom of this page for more details.

Return value:
0 if everything was OK, or a string begining with a non-zero number that explains what went wrong.

Example:

to = "someone@some-company.com" $
from = "teebo@mw-interactive.co.uk" $
r = sendmail(to$, from$, "Aptilis mail", "Hi,\nhow are you?") $
if r = 0
print("The message has been sent\n")
else
// error
print(r$)
end if
Note: You can use the '\n' escape sequence to indicate a new line.

Mail messages whose 'from' address is not known to the smtp server you use may be rejected with a 553 error.
To make sure your message will be sent, use an address known to your smtp server in the 'From' parameter.
From Build 040-0009, there is an extra parameter you can put in sendmail. This fifth parameter is the 'reply-to' field, so that, even if the 'from' is incorrect, when you hit the 'reply' button in your mail program, the address used to reply to will be the one coming from that 5th parameter.
For example, if you have a web form with a from address from the person who has filled the form,
use the sendmail command like this:

sendmail("you@your.isp.com", "knownAdress@your.isp.com", " a subject", "bla-bla", from$)
Say the guy's e-mail is "bob@jello.com", and that's what from$ contains. (It's coming from the web form)
Note that 'knownAddress' could be 'you'.
You will receive a message from knownAdress@your.isp.com
but when you hit 'reply', the message will be set go back to: bob@jello.com instead

See also: sendMIMEMessage, setSMTPSever, readEMails.