Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why does forwarded email get hosed and not work in LSL?

Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-26-2006 21:23
I'd like to be able to have my products send an email when they are rezzed to an email address on my own server, for example [email]updatecheck@mysever.com[/email]. I have forwarding set up for that email address to [email]key@lsl.secondlife.com[/email], so if I ever change, by accident or on purpose, the key to which the update emails need to come, I can change where they emails are forwarded.

However, when I test this, the emails just don't work. If I send an email directly to the [email]key@lsl.scondlife.com[/email], it triggers the email event and my script works. However, if I use the forwarded address, nothing happens.

What's going on and is there a workaround, fix, etc?

Thanks!

Aaron
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
07-26-2006 21:31
In the process of forwarding the message, does it make any changes to the message? If it does not then its possible it's getting eaten by an anti-spoof script.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Adriana Caligari
Registered User
Join date: 21 Apr 2005
Posts: 458
07-26-2006 22:29
In either your llGetNextEmail or email section are you checking and filtering the address ?

If so add some debug to see what the address is, and adjust if required.

I had similar when I forwarded an email LSL picked it up as coming from my server box address not the adress I forwarded it from.
_____________________
Maker of quality Gadgets
Caligari Designs Store
Kelly Linden
Linden Developer
Join date: 29 Mar 2004
Posts: 896
07-26-2006 22:51
Forwarding can be problematic with email->lsl. Essentially there is *not* an actual mailbox for each address, there is a catch all that passes to a script that relies on the To field to send the email to the right place.

The place where forwarding can jack things up is that the To address on strictly forwarded email remains what it originally was. In other words our servers receive a message To "forwarder@myserver.com" instead of To "key@lsl.lindenlab.com". At this point we just don't know how to forward it to the right script and thus it is lost.

I hope this makes sense. :)
_____________________
- Kelly Linden
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-27-2006 08:10
Hmmm... that does make sense.

Does anyone know of a way to use a pipe or something to receive an email, pick it apart line-by-line, and then create a brand new email that DOES have the To: field so lsl.secondlife.com can process it?
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-27-2006 08:35
I just finished an SMTP server you could use to receive email. Its written in C#, so you can take advantage of the SMTP client built in there to send the message to the object.

Its pretty easy to use, just instantiate a server object, register a receiving username, and register an EmailReceived event handler. I will post the code as soon as I can (I'm at a public terminal right now) :)
==Chris
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-27-2006 08:43
procmail - you would be able to use it to, say, pipe the mail into a perl script that strips the header (look for a blank line), strips the object added header if you want (look for another blank line) and fires off a brand new mail with the rest (the original body) as the body.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-27-2006 08:45
From: Aaron Levy
Hmmm... that does make sense.

Does anyone know of a way to use a pipe or something to receive an email, pick it apart line-by-line, and then create a brand new email that DOES have the To: field so lsl.secondlife.com can process it?


I'm almost done with an C# SMTP server that would help you out in that arena. All I have left to do is parse the email for its headers. I have it on the backburner for now, as Im working on something for libsecondlife.

I would gladly finish it up for you as a commission, however :)
==Chris
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-27-2006 14:03
From: Bitzer Balderdash
procmail - you would be able to use it to, say, pipe the mail into a perl script that strips the header (look for a blank line), strips the object added header if you want (look for another blank line) and fires off a brand new mail with the rest (the original body) as the body.


Yeah, procmail looks good. Now to wrap my head around it. Are you familiar with it? Here's some code for forwarding email to a gmail adddress I might be able to adapt. You can change the email's TO: header:


~/.procmailrc
CODE

# your remote address
WHERETO=xyz@gmail.com

# uncomment next two lines for debugging
#LOGFILE=$HOME/procmail.log
#VERBOSE=yes

# you need to set a shell to use formail
SHELL=/bin/sh
:0c
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-Loop: to_gmail
| (formail -t -I"To: $WHERETO" \
-A"X-Loop: to_gmail" \
) | $SENDMAIL -t
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
07-27-2006 14:52
Aaron Levy, is the only purpose for using the email for updating dating key information and relaying back to SL? If so I might have a more simple solution. It involves a couple small CGI scripts and using llHTTPRequest. plus much faster and reliable.

I had the same problem a few months back after one of my main prims got returned do to some server glitch and broke a major update system I had running. Tried the Email thing and became frustrated after asking support if there servers were blocking all forwarded emails, basically the response was you cannot email into SL. PFFT!
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-27-2006 14:54
I used procmail to send the email to a PHP script. Then I found a PHP email parsing script somewhere online (maybe it's in the Wiki). All it does is parse the headers and extract the subject and the message. You then build a new email with the same subject and body, but in the To field, you fill in the actual [email]key@lsl.lindenlab.com[/email] that you want to send it to (which is basically calling one PHP function). That seems to work pretty well. I'm sure you could do it with Perl/Python/whatever, I just found the PHP example script first. Sounds like procmail can do this directly too, but I didn't try figuring it out that far :)
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-27-2006 15:13
Ziggy, that sounds so much easier, yes. I searched the Wiki and didn't see such a script there. Perhaps you could send me a copy or post it here?

aaronlevy (at) gmail (dot) com

Thanks!
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-27-2006 16:01
The third post in this thread has the basics of what you need:

/54/8c/53510/1.html

Copy the stuff till the end of the for() loop, that's parsing the email and separating out the fields. At the end of that, $subject contains the subject, and $message is the message. Then all you need to do is add a line that goes:

CODE
mail("key@lsl.lindenlabs.com", $subject, $message, "");


I forget what the last "" is for. Play with this, and you should be able to figure something out. My scripts also parse the data in $message and extract stuff from it, so what I posted isn't exactly what I do, but hopefully that should get you started in the right direction.
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-27-2006 21:59
Awesome, Ziggy -- that's definitely the direction I want to go with it.

Here's my code:

CODE
#!/usr/bin/php 
<?php
require("xml-rpc.php");
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

$lines = explode("\n", $email);

$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {

$headers .= $lines[$i]."\n";


if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {

$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {

$splittingheaders = false;
}
}

mail("my@emailaddress.com", $subject, $message, "");
?>



I have it going to my email address right now for testing, but nothing's ever coming through, and I can't figure out how to test it from the command line. When I run my script from the command line, I get:

CODE
Status: 404
X-Powered-By: PHP/4.4.2
Content-type: text/html

No input file specified.


I found a link in the forums here to an xml-rpc.php to use, as not having one the script would just break right on line 2.

Any ideas?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
07-28-2006 01:42
Two things... are you piping the incoming email to the script properly?

What's the fourth element in the mail() command for?

I've used this script, more or less (I don't think you need the include xml-rpc.php line either, you're not using xmlrpc that I can see for example) a number of times, and the likliest error is the email not reaching it. You can check for that by commenting all your script out and putting in mail(your_address, "got it", "";); so that if there's an email received you get a notification - it's the major pain of this method.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-28-2006 08:32
Thanks everyone! Eloise was correct, the email was never reaching my php program, so I did some searching and had to add "php -q" before my "/path/to/file.php" to get it to work. All good now!

Thank you thank you thank you!
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-28-2006 08:40
Well, I take that back. My script is processing the email and sending it off -- when I send the email to my gmail account to look at, it looks fine. When I send it to the item in-world, still nothing happens.

Is there a script I can drop into an object in-world that will just spit out an email it receives line by line so I can see what its getting, if anything?
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-28-2006 08:46
this _should_ pick up and dump one email on a touch, also telling you how many are queued still.

Can't get inworld to test it tho

CODE

default {
touch_start(integer n) {
llGetNextEmail("","");
}

email(string t, string a, string s, string m, integer n) {
llSay(0, "Time : " + t);
llSay(0, "Addr : " + a);
llSay(0, "Subj : " + s);
llSay(0, "Body\n" + m);
llSay(0, "Num remaining to get is " + (string)n);
}
}
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-28-2006 09:46
From: someone
What's the fourth element in the mail() command for?


OK, I looked that up, and it's an optional parameter - additional headers. Like I said, I just copied that script, and it worked for me.

From: someone
Well, I take that back. My script is processing the email and sending it off -- when I send the email to my gmail account to look at, it looks fine. When I send it to the item in-world, still nothing happens.


There's another check you can run, in addition to Bitzer's script. Try sending an email to that object key from your Gmail account. That will independently test the 'back' half of the connection, now that you know the 'front' half (i.e. email -> PHP script -> email) is working. It could be something as silly as a typo in the key of the object. You did use [email]key@lsl.lindenlabs.com[/email], right?