Skip to content

Inter‐object email with llEmail()

lickx edited this page Dec 2, 2024 · 27 revisions

Inter-object email with llEmail() can be the foundation of more advanced LSL projects. Think of networked-vendors, inter-sim teleportation networks etc.

An object's email address is always in the form [email protected]

  • The uuid in the address is exactly what llGetKey() returns in an LSL script residing in an object/linkset.
  • Unlike URLs returned by llRequestURL(), a rezzed object's uuid/key never changes and is static; unless the object is re-rezzed, re-linked[?] or loaded from an OAR!
  • The server part of the address can be overridden from the default by changing the internal_object_host setting in OpenSim.ini

When an object emails another object, the mail doesn't use or need SMTP, unless the destination is on another grid.

  • If the destination object exists on the sending objects' region, IMAP is bypassed by directly placing the mail in the region's mail queue, from where the destination object will retrieve it with llGetNextEmail().
  • If the destination exists on another region, the email will be put in the IMAP inbox; and automatically retrieved from IMAP when the destination object calls llGetNextEmail(). This is a new feature only in OpenSim/lickx.

You just need one dedicated, local or remote IMAP account for all sims and objects. What follows are instructions on setting up your own IMAP server.

DISCLAIMER: This feature is designed to use a dedicated IMAP account solely meant for lsl mail! While I went out of my way to ensure my code works correct, I am in no way responsible for any loss of e-mails should you decide to use this on your regular home/work IMAP account!

To enable inter-sim object email, an IMAP server will need to be setup. SMTP is not required.

apt-get install courier-imap

By default it listens on ipv6 only, not ipv4. We can fix that:

sudo vim /etc/courier/imapd

Change ADDRESS=0 to ADDRESS=0.0.0.0

You should block port 143 and 993 on your firewall, only opening it to localhost and optionally to any other simservers you own (or your grid's private subnet).

Using Courier without TLS (port 143)

Run without TLS only if you limit access (firewall) to localhost or your own private servers or subnet. To disable the SSL version of Courier:

sudo service courier-imap-ssl stop
sudo systemctl disable courier-imap-ssl

Using Courier with TLS (port 993)

For Let's Encrypt support, see https://github.com/nicolas-dutertry/letsimap.

To disable the non-TLS version of courier:

sudo service courier-imap stop
sudo systemctl disable courier-imap

Making a user with a Maildir

You'll want a dedicated (linux) user account just for lsl mail. This user will need a Maildir folder, which is a folder tree specifically designed to handle e-mail in a non-blocking way:

sudo adduser lslmail
(follow instructions)

su lslmail
maildirmake.courier ~/Maildir
or
maildirmake ~/Maildir
exit

Set up Mutt for reading/debugging email

It is useful to have a mail client to inspect any messages objects send, at least while setting up the mail system. Alpine doesn't work well with Maildir, but Mutt does:

sudo apt-get install mutt

Then, create the file /etc/Muttrc.d/maildir.rc with the following contents:

set mbox_type=Maildir

set spoolfile="~/Maildir/"
set folder="~/Maildir/"
set mask="!^\\.[^.]"
set record="+.Sent"
set postponed="+.Drafts"

mailboxes ! + `\
for file in ~/Maildir/.*; do \
  box=$(basename "$file"); \
  if [ ! "$box" = '.' -a ! "$box" = '..' -a ! "$box" = '.customflags' \
      -a ! "$box" = '.subscriptions' ]; then \
    echo -n "\"+$box\" "; \
  fi; \
done`

macro index c "<change-folder>?<toggle-mailboxes>" "open a different folder"
macro pager c "<change-folder>?<toggle-mailboxes>" "open a different folder"

(taken from https://wiki.debian.org/Mutt but should work for Ubuntu too)

Now you can run mutt to use and inspect mails in the inbox that have not been retrieved yet by objects (until those objects call llGetNextEmail()):

sudo su lslmail
mutt

OpenSim.ini example

Assumes a non-TLS Courier on localhost, with no SMTP server (outbound email disabled):

[Startup]
emailmodule = DefaultEmailModule

[EMail]
enabled = true
enableEmailToExternalObjects = true
enableEmailToSMTP = false

IMAP_SERVER_TLS = false
IMAP_SERVER_HOSTNAME = 127.0.0.1
IMAP_SERVER_PORT = 143
IMAP_SERVER_LOGIN = lslmail
IMAP_SERVER_PASSWORD = yourpassword

Mail between objects and the outside world

This can be realized by running a SMTP service such as postfix, which would put all incoming mail (catchall) addressed to [email protected] (internal_object_host would then be defined as lsl.yourgrid.com) in the maildir of the linux user that handles lsl mail (for example '/home/lslmail/Maildir'). The program 'procmail' can help with this.

Running a SMTP service is an advanced topic and should not be taken lightly, a misconfigured or insecure service can mean you land on several blacklists. If in doubt, don't do it and keep mail grid-local with IMAP; or outsource SMTP to a professional service.

About availability and safeness of enabling e-mail

Basic object to object mail was always possible (within the boundaries of a sim), even in upstream OpenSim, it was just disabled. I have enabled this as the default in Lickx because some scripts do use llEmail. In this config, mail destined for external servers is silently discarded (any address NOT ending in internal_object_host, set in OpenSim.ini) Use the following config:

[Email] (this is [SMTP] in upstream OpenSim.ini)
    enabled = true
    enableEmailToSMTP = false
    enableEmailToExternalObjects = false

More advanced object to object mail, that works between different simulators if those simulators are configured to use the same IMAP inbox, can be enabled in OpenSim/lickx:

[Email] (this is [SMTP] in upstream OpenSim.ini)
    enabled = true
    enableEmailToSMTP = false
    enableEmailToExternalObjects = true
    ; (fill in IMAP server details)

And lastly if you want mail to also leave and enter the grid (this is the most difficult to setup safely):

[Email] (this is [SMTP] in upstream OpenSim.ini)
    enabled = true
    enableEmailToSMTP = true
    ; (fill in SMTP server details)
    enableEmailToExternalObjects = true
    ; (fill in IMAP server details)

Portable LSL method of getting object mail hostname

string GetMailHostname()
{
    string sHostname = llGetEnv("mailname");
    if (sHostname == "") {
        string sChannel = llGetEnv("sim_channel");
        if (llSubStringIndex(sChannel, "Second Life")==0) return "lsl.secondlife.com";
        else if (llSubStringIndex(sChannel, "OpenSim")==0) return "lsl.opensim.local"; // vanilla OpenSim
    }
    return sHostname; // OpenSim/lickx (internal_object_host in OpenSim.ini)
}

default
{
    state_entry()
    {
        llOwnerSay("The email address of this prim is "+(string)llGetKey()+"@"+GetMailHostname());
    }
}