Skip to content
lsl.devlsl.devLSL Dev

Email-to-IM

LSL Header: {{LSL Header}}

Email-to-IM

This is a basic script to translate emails into IMs. When initiated, the script says an email address, which is the UUID for the prim containing the script along with the lsl email domain. The body of any email sent to the address will be relayed as an object IM to the owner in SL. And a timestamp is included which is the time LL received the email (as opposed to the time the email is transmitted via IM).
The prim containing this script must have a stable UUID for longterm continued usage. This means, the object can not be taken into inventory and re-rezed.
You are welcome to correct, add features or otherwise improve the script.
// Email-to-IM
// DoteDote Edison

///////// constants /////////
// how often to check for new email when owner is online (seconds)
float FAST = 60.0;
// how often to check owner online status when owner is offline (seconds)
float SLOW = 300.0; 
// timezone offset from UTC
integer OFFSET = -4;

////////// globals //////////
key request;
key owner;
integer owner_online;

string GetStamp(string time) {
    list weekdays = ["THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"];
    integer a = (integer)time + (OFFSET*3600);
    integer hours = a/3600;
    integer mins = a/60;
    string day  = llList2String(weekdays, (hours/24)%7);
    return (string)(hours%24) + ":" + (string)(mins%60) + " " + day;
}

default {
    state_entry() {
        owner = llGetOwner();
        string address = (string)llGetKey() + "@lsl.secondlife.com";
        llSetText("Email Server\nOnline", <0.25, 1.0, 0.25>, 1.0);
        llOwnerSay("Now online.  The Email-to-IM address for " + llKey2Name(owner) + " is:\n" + address);
        llSetTimerEvent(FAST);
    }
    on_rez(integer start_param) {
        llResetScript();
    }
    touch_start(integer num_detect) {
        if (llDetectedKey(0) == owner) state off;
    }
    email(string time, string sender, string subject, string body, integer num_remain) {
        llInstantMessage(owner, "Email Received from: " + sender + " -- " + GetStamp(time));
        llInstantMessage(owner, body);
        if (num_remain > 0) llGetNextEmail("", "");
    }
    dataserver(key query, string data) {
        if (query == request) {
            request = "";
            if (data == "1") {
                owner_online = TRUE;
                llSetTimerEvent(FAST);
            }
            else {
                owner_online = FALSE;
                llSetTimerEvent(SLOW);
            }
        }
    }
    timer() {
        request = llRequestAgentData(owner, DATA_ONLINE);
        if (owner_online) llGetNextEmail("", "");
    }
    state_exit() {
        llSetTimerEvent(0.0);
        llSetText("Email Server\nOffline", <1.0, 0.25, 0.25>, 1.0);
    }
}

state off {
    touch_start(integer num_detect) {
        if (llDetectedKey(0) == owner) state default;
    }
    on_rez(integer start_param) {
        llResetScript();
    }
}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from Email-to-IM, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.