Difference between revisions of "LlEmail"

From Second Life Wiki
Jump to navigation Jump to search
Line 31: Line 31:
{{!}}}
{{!}}}
|caveats=* There is a limit to the number of email messages an object can send in a given amount of time.  
|caveats=* There is a limit to the number of email messages an object can send in a given amount of time.  
* There is a limit of 500 messages from a single agent's objects in a one hour period
* There is a limit of 500 messages from a single agent's objects in a one hour period.
* (Sept-2008) The Email Throttle was modified slightly, Per Prospero Linden's comments: "there has long been a throttle that makes a single script sleep for 20 seconds after sending an email. The new throttle is per user... some were using many, many different scripts to send spam. (the new throttle applies) when the destination is outside of Second Life. I know that messages within the same region were not throttled (beyond the 20-second delay), and I *believe* that messages between different sims were not throttled (between the 20-second delay)."
* Due to the bug {{Jira|SVC-23}} (present since 2005), objects may stop receiving emails completely until either the region is restarted or the object crosses a region boundary (resetting the script doesn't help).  Emails sent may eventually be received after a restart/region-cross.  Hence, don't rely on this function for reliable inter-region messaging.  
* Due to the bug {{Jira|SVC-23}} (present since 2005), objects may stop receiving emails completely until either the region is restarted or the object crosses a region boundary (resetting the script doesn't help).  Emails sent may eventually be received after a restart/region-cross.  Hence, don't rely on this function for reliable inter-region messaging.  
|constants
|constants

Revision as of 08:44, 1 October 2008

Summary

Function: llEmail( string address, string subject, string message );
20.0 Forced Delay
10.0 Energy

Sends an email to address with subject and message.

• string address
• string subject
• string message

The entire message (including the address, subject and other miscellaneous fields) can't be longer than 4096 bytes combined.

Specification

The message is prefixed with information about the prim sending the email.

Template Example
Object-Name: *prim*
Region: *simname* (*simpos.x*, *simpos.y*)
Local-Position: (*primpos.x*, *primpos.y*, *primpos.z*)

*message*
Object-Name: Object
Region: Gibson (254976, 256000)
Local-Position: (117, 129, 50)

The real message starts here.

Caveats

  • This function causes the script to sleep for 20.0 seconds.
  • There is a limit to the number of email messages an object can send in a given amount of time.
  • There is a limit of 500 messages from a single agent's objects in a one hour period.
  • (Sept-2008) The Email Throttle was modified slightly, Per Prospero Linden's comments: "there has long been a throttle that makes a single script sleep for 20 seconds after sending an email. The new throttle is per user... some were using many, many different scripts to send spam. (the new throttle applies) when the destination is outside of Second Life. I know that messages within the same region were not throttled (beyond the 20-second delay), and I *believe* that messages between different sims were not throttled (between the 20-second delay)."
  • Due to the bug SVC-23 (present since 2005), objects may stop receiving emails completely until either the region is restarted or the object crosses a region boundary (resetting the script doesn't help). Emails sent may eventually be received after a restart/region-cross. Hence, don't rely on this function for reliable inter-region messaging.

Examples

<lsl> string email_address = "somebody@example.com"; // who will receive the messages

default {

   state_entry() {

       //Send an email to a normal email account
       llEmail( email_address, "Look it's an email subject line!", "Testing 1 2 3" );
   }

   touch_start( integer num_detected ) {
       integer i = 0;

       // Send another email, telling who touched the prim.
       do
           llEmail( email_address, "No touching!", "I was defiled by: " + llDetectedName(i) + "\nKey: " + (string) llDetectedKey(i) );
       while(++i < num_detected);
   }

}

</lsl>

Useful Snippets

<lsl> email( string time, string address, string subj, string message, integer num_left ) {

   if(llGetSubString(address, -19, -1) == "@lsl.secondlife.com")//trim the header
       message = llDeleteSubString(message, 0, llSubStringIndex(message, "\n\n") + 1);

} </lsl>

Notes

  • Because of the long delay on this function, it is often called from a second script triggered by link_message.
  • If you are sending email to a prim within Second Life, its address is [key]@lsl.secondlife.com
    • Which means if the key returned by llGetKey is "a2e76fcd-9360-4f6d-a924-000000000003", then its email address is "a2e76fcd-9360-4f6d-a924-000000000003@lsl.secondlife.com".
    • Agents do not have fixed email addresses, use llInstantMessage or llOwnerSay.

Prim2Prim Email

In LSL you can both send email with llEmail and receive it with the email event.


The email event is triggered with 5 pieces of information.

• string time When the message was sent, in the (string)llGetUnixTime format
• string address Who sent the message
• string subject Subject of the message
• string message Body of the message
• integer num_left The number of emails left in the email queue


When receiving a message sent with llEmail it helps to separate the message from the prefixed header. The header and original message body are separated by "\n\n"

<lsl>integer divide = llSubStringIndex(message, "\n\n"); string header = llDeleteSubString(message, divide, -1); message = llDeleteSubString(message, 0, divide + 1);</lsl>

To get just 1 of the header items, do this: <lsl>list lines = llParseStringKeepNulls(header, ["\n"], []); string objname_line = llList2String(lines, 0); string region_line = llList2String(lines, 1); string localpos_line = llList2String(lines, 2);</lsl>

To get a pure region name, do this: <lsl>string region_name = llStringTrim(

           (string)llDeleteSubList(
               llParseStringKeepNulls(
                   llDeleteSubString(region_line, 0, 12),
                   [], 
                   ["("]
               ), -2, -1), STRING_TRIM);</lsl>

This application uses email to have objects check with a central server to see if the owner has the latest version. In the objects: <lsl>string version = "1"; // string type = "lolcube"; default {

   on_rez(integer start_param)
   {
       llEmail("5a634b27-f032-283f-2df2-55ead7724b23@lsl.secondlife.com",
           version,
           (string)llGetOwner() + "," + type);
   }

}</lsl> The server: <lsl>default {

   state_entry()
   {
       llSetTimerEvent(15.0);
   }
   
   timer()
   {
       llGetNextEmail("", "");
   }
   
   email( string time, string address, string version, string message, integer num_left )
   {    
       if ((integer)version < 2)
       {
           list info = llCSV2List( llDeleteSubString(message, 0, llSubStringIndex(message, "\n\n") + 1));
           llGiveInventory(llList2Key(info,0), llList2String(info,1));
       }
       
       if(num_left)
           llGetNextEmail("","");
   }

}</lsl>

See Also

Events

• email
• link message

Functions

• llGetNextEmail
• llMessageLinked

Deep Notes

Signature

function void llEmail( string address, string subject, string message );

Open Source Portal

Feature Design Document

(none)

Functional Spec

(none)

Test scripts

internal test

Discussion for future improvements

(none)

Relationship to other features

List of features that need to be tested when this feature changes, and why.

IM to email - verify IM -> email still works.

Postcards - Postcards use email out?


User Guides

llEmail on LSLwiki.net