Hamster-Scripts: Functions (Hamster): Mails

Mails

HamMailExchange( <server-list> )
HamMailExchange

Not supported any more, use "HamFetchMail" and "HamSendMail" instead.

HamFetchMail( <server>, <port>, <user>, <pass>, <destuser>, <filter>, <leave> )
...
HamFetchMail( <server> )

Starts a thread, which fetches mails from the given POP3-server (<server>, <port>).

If <user> (username) and <pass> (password) are given, they will be used to login to the server, if they are both empty, the password-setting for the given server is used. Furthermore, one of the stored "general-purpose"-passwords can be used here to avoid noting it in clear-text in the script (<user>="$(number), <pass>="").

If <destuser> is given, fetched mails will be stored in the mailbox of this user, "admin"-mailbox is used otherwise.

If <filter> is given, it determines the filter-section to use for the mails fetched with this commands (default is global filters only, i.e. "[*]"-section in MailfFilt.hst).

If <leave> is given, it overrides any default settings regarding "leave mails on server". A value of "1" always leaves mail on server, a value of "0" deletes them after loading.

Returns: 0=OK/Started, <>0=Not started

HamFetchMail( "pop3.serv.er", "pop3", "", "", "", "", "1" )
HamFetchMail( "pop3.serv.er", "", "john.doe", "secret", "john", "" )
HamFetchMail( "pop3.serv.er", "10110", "$7", "", "jane", "" )
HamFetchMail( "pop3.serv.er", "", "$42", "", "admin", "myfilters" )

HamSendMail( <server>, <port>, <from-select>, <to-select> )
...
HamSendMail( <server> )

Starts a thread, which sends mails to the given SMTP-server (<server>, <port>).

If no <from-select> and no <to-select> is given, all mails waiting for delivery are sent. If selections are given (regular expressions), only mails with a matching Envelope-From/-To are sent to this server.

Returns: 0=OK/Started, <>0=Not started

HamSendMail( "smtp1.serv.er", "smtp", "john\.doe@serv\.er" )
HamSendMail( "smtp2.serv.er" )

HamSendMailAuth( <server>, <port>, <user>, <pass>, <from-select>, <to-select> )
...
HamSendMailAuth( <server> )

Like "HamSendMail" above, but additionally allows to provide username and password used for authentication.

Note: Username and password are ignored, if SMTP authentication is not enabled for the given server.

Returns: 0=OK/Started, <>0=Not started

HamSendMailAuth( "smtp3.serv.er", "smtp", "$42", "", "@smtp3\.serv\.er" )

HamSendMailMX

Starts a thread, which sends mails in MX mode, i. e. Hamster tries to detect the mail exchange (MX) servers of mail recipients and then sends the mails directly to these servers.
See "Reference: File SmtpRouter.hst" for additional info on this MX mode.

Returns: 0=OK/Started, <>0=Not started

# Try to send mails in MX mode
HamSendMailMX
HamWaitIdle
# Send remaining mails to provider's server
HamSendMail( "mail.provid.er" )
HamWaitIdle

HamNewMail( <EnvelopeFrom>, <EnvelopeTo>, <Mailtext> )

Send a new mail as if it had been sent to Hamster's SMTP server.

<EnvelopeFrom> is the sender of the mail, <EnvelopeTo> are the recipients separated by ";". Both envelope values may contain the name of local users like "admin".

<Mailtext> is the mail to send. It contains header lines, an empty line as header/body separator and finally the text of the message. If required "Date:" or "From:" headers are missing, they will be added automatically.

WARNING: Using HamNewMail from within an action script may cause HService to "hang", as HamNewMail itself will trigger further actions. If at all, only use it in action scripts, which do NOT have the "[X] Lock" option marked!

Returns: 0=OK, <>0=Failed

varset( $EnvFrom, "admin" )
varset( $EnvTo, "admin;john.doe@remote.address;jane.doe@remote.address" )
varset( $MailText, ListAlloc )
ListAdd( $MailText, "From: admin" )
ListAdd( $MailText, "To: (various recipients)" )
ListAdd( $MailText, "Subject: Mail by Script!" )
ListAdd( $MailText, "" ) # header/body separator
ListAdd( $MailText, "This mail was sent by script!" )
HamNewMail( $EnvFrom, $EnvTo, ListGetText($MailText) )
ListFree( $MailText )

[www.elbiah.de Hamster Playground Documentation]