Inter‐object email with llEmail()
Lotek edited this page 2026-02-28 10:56:49 +01:00

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 uuid@lsl.opensim.local

  • 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, 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.

Fun fact: since inter-sim e-mail happens through a shared IMAP inbox, any simulator under your control that uses this inbox can be interconnected. For instance you may want to exchange mail between objects on a sim you have attached to osgrid, with simulators on your own grid.

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. We use Courier here in the example, but another popular IMAP server is Dovecot.

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).

On Debian, Courier fails to autostart on boot. To fix this, edit /etc/init.d/courier-imap and /etc/init.d/courier-imap-ssl, and add $network to the line beginning with '# Required-Start' so it reads:

# Required-Start:    courier-authdaemon $remote_fs $syslog $network

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

Outbound mail to outside can be setup by configuring the SMTP settings.

Inbound mail from outside can be setup in two ways:

The hard way (especially keeping it secure) is running your own mail server accepting mails for the lsl subdomain, with procmail moving any mail for the lsl subdomain to the lslmail user's Maildir. Running your own SMTP service is an advanced topic and should not be taken lightly, a misconfigured or insecure service can mean you land on several blacklists.

The easy way is purchase a mail service for the lsl subdomain, and then setup a catch all for the subdomain. Setup a cron job to getmail/fetchmail from the remote server to your own server every 5 or 10 minutes. More info here. In OpenSim.ini you would use your local IMAP, to avoid your mail provider getting hammered by llGetNextMail() in poorly written lsl scripts. This way mail from within the grid will be instant, while mail from outside the grid will be at the frequency of your cronjob.

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 != "") return sHostname; // OpenSim/lickx (internal_object_host in OpenSim.ini)
    string sChannel = llGetEnv("sim_channel");
    if (llSubStringIndex(sChannel, "Second Life")==0) return "lsl.secondlife.com"; // Second Life
    else if (llSubStringIndex(sChannel, "OpenSim")==0) return "lsl.opensim.local"; // vanilla OpenSim
}

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