SRL Archive - SRL Member Goodies

How To Get SCAR To Email You


TRiLeZ

2009-07-10 10:59:19

SCAR-PHP Emailer


Over the past 24 hours, I have thought of a really usefull function to make. It could email you whenever you want it to. For example: when a script your using finishes and your not at the computer, SCAR would email the person using the script. If you had a cell that had email, you could read the message and be like oh, the script has finished, lets see why and start it up again. This function would be so usefull and I decided to build it and here it is:

You can customize this email message to whatever you want. You can change:

  • The Person Recieving The Email.. of Course
  • The Subject
  • The Message
  • The Sender's Email :eek:
  • The Sender's Name :eek:

To start off, you will have to have a webhoster with PHP built in.
If you dont have one just search up free webhosting or something.


Here is my source code for the SCAR-PHP Emailer:

<?php
if (isset($_POST['email']) && isset($_POST['message']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['sender']))
{
$MyEmail = $_POST['email'];
$EmailMessage = $_POST['message'];
$SenderName = $_POST['name'];
$EmailSubject = $_POST['subject'];
$SenderEmail = $_POST['sender'];
$Headers = "From: {$SenderName} <{$SenderEmail}>";

if (empty($email))
{
echo "Error";
} else {
exit;
}
}
?>

<form method="post" action="<?=mail($MyEmail,$EmailSubject,$EmailMessage,$Headers);?>">
<input type="hidden" name="email" value="N/A" />
<input type="hidden" name="message" value="N/A" />
<input type="hidden" name="name" value="N/A" />
<input type="hidden" name="subject" value="N/A" />
<input type="hidden" name="sender" value="N/A" />
</form>

Remember to save that as a .php :p

Now the SCAR function to send the email:



{*******************************************************************************
function SendEmail(MyEmail, Subject, EmailMessage, SenderEmail, SenderName, Website: string): Boolean;
By: TRiLeZ
Description: Sends an email using PHP and SCAR.
*******************************************************************************}
function SendEmail(MyEmail, Subject, EmailMessage, SenderEmail, SenderName, Website: string): Boolean;
var
Email : string;
Client : Integer;
begin
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
Wait(20);
AddPostVariable(Client, 'email', MyEmail);
AddPostVariable(Client, 'message', EmailMessage);
AddPostVariable(Client, 'name', SenderName);
AddPostVariable(Client, 'subject', Subject);
AddPostVariable(Client, 'sender', SenderEmail);
Email := PostHTTPPageEx(Client, Website);
FreeHTTPClient(Client);
if (Email > '') then Result := true
else
begin
Result := false;
Writeln('Emailing User Failed!');
end;
end;

How do you send the email with that? Heres how:
Call: SendEmail('', '','', '', '', '');
Heres how you would fill that ^ in:
SendEmail('myemail@domain.com', 'SUBJECT', 'MESSAGE', 'SenderEmail', 'SenderName', 'website@domain.com');

Build this in with your scripts you make and they will kick ass :D
Remember to use constants to make things easier for the script user.
Just to let you know, SCAR will ask the script user if they want to allow SCAR to connect to the website, so if they arent there, they wont get their email until they allow the connection, so try to connect to your website and tell the script users to always allow connection to that site.

For your script, you could modify the PHP file and my function so the message, subject, sender and whatever is in the PHP file.

I think thats about it :spot:
Please give comments and suggestions. Feel free to ask questions and give rep :)

noidea

2009-07-10 11:11:01

This is AMAZING
Repped

Harry

2009-07-10 11:13:11

Most free hosts with email sending options are marked as spam and instantly discarded by email providers. But nice work anyways I suppose, good luck finding a PHP with mail() that is not spammed out.

TRiLeZ

2009-07-10 11:24:17

From: Harry
Most free hosts with email sending options are marked as spam and instantly discarded by email providers. But nice work anyways I suppose, good luck finding a PHP with mail() that is not spammed out.


Ive never heard of that… im using free hosting with 000webhost and everything runs smootly. But if the email is from an unknown domain it could get marked as spam or said to be dangerous. I use hotmail btw. If you set SenderEmail to something with a domain of hotmail.com or live.com or live.ca or shaw.ca or anything thats know not to be spam then it will go the the email inbox and wont be marked as dangerous.

Harry

2009-07-10 11:33:04

From: TRiLeZ
Ive never heard of that… im using free hosting with 000webhost and everything runs smootly. But if the email is from an unknown domain it could get marked as spam or said to be dangerous. I use hotmail btw. If you set SenderEmail to something with a domain of hotmail.com or live.com or live.ca or shaw.ca or anything thats know not to be spam then it will go the the email inbox and wont be marked as dangerous.

Well,
1) It is against the law to send email with a spoofed domain name; it is easy to do, but against the CAN-SPAM act of 2003.
2) Most good email programs look at the sending server, not the sender's domain name.
3) Use Gmail :p

marpis

2009-07-10 11:33:36

Rep++ :) Im gonna make my scripts send the proggies to me!

EDIT: I got it working! This is the most awesome thing ever ^^ Now i can see if ppl use my scripts and don't post proggys ;)

noidea

2009-07-10 11:34:56

AMG I got it working!
Greaat awsome guide.

I used 00webhost. I use GMail. it didn't get marked as spam.

I also sent to my phone.

1) Text your email (used to get your adress thingy)
2) use the adress from the text (example: [email]9135556843@vtext.com[/email])
3) put that in the email spot
4) Proffit

Gu3st...

2009-07-10 16:39:40

Wouldn't it be better to have it save the stuff as a page? Like www.something.co.uk/proggie?
Also this has been invented many times before ;)
It is nice though :D Good work!

Wizzup?

2009-07-10 16:59:18

I think you'd have more luck writing a SMTP client. (Which isn't really hard)

Awkwardsaw

2009-07-10 18:28:25

oh. wow. AMAZING. i will use this fo sho :D. + rep

also, can you explain the process of setting up 00webhost, and the PHP page? i made an account and it seems like thers 10 different things i need to do

JPHamlett

2009-07-11 02:30:12

can someone explain ot me how to do this is non tech savvey wrods cause i cant get it to work

TRiLeZ

2009-07-11 03:20:22

Ill make a vid tutorial on how to setup the website and upload the php file

Awkwardsaw

2009-07-11 03:52:50

thanks TRiLeZ :p

Da 0wner

2009-07-11 04:18:30

Your form you don't even need…

You can retrieve post variables without a form.

Lance

2009-07-22 14:21:29

wow this is actualy amaseing. and i think the best part is that YES we can have our scripts text our cell phones when it runs into a problem.. this could deffinatley be the next level of botting haha.
Atm im running my scripts to play a alert sound if my attention is needed, but if i set it up to text my cell phone i could be anywhere in my house out of range of my computers speakers ;D

Freddy1990

2009-07-23 02:52:55

You can actually have SCAR mail you for real without a php script if you connect to an stmp server =P

Naum

2009-07-24 00:54:02

From: Freddy1990
You can actually have SCAR mail you for real without a php script if you connect to an stmp server =P


Is that what your complaint system does?

Awkwardsaw

2009-07-24 07:54:18

From: Freddy1990
You can actually have SCAR mail you for real without a php script if you connect to an stmp server =P


care to enlighten us? =D

Freddy1990

2009-07-24 23:02:55

From: NaumanAkhlaQ
Is that what your complaint system does?


No, I could've have it mail me directly, but I decided that was counterproductive so I went with http protocol for that and my server mails me when a progressreport has been uploaded.

From: Awkwardsaw
care to enlighten us? =D


http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol

Smtp protocol is pretty easy, as the name suggests…

Heysus

2009-08-02 00:11:44

From: Wizzup?
I think you'd have more luck writing a SMTP client. (Which isn't really hard)


I spent a good 4 hours trying to write an SMTP client but this is all i got:
c := OpenConnection('smtp.gmail.com', 587, 1000);
ReadConnectionData(c, s);
Writeln(s);
Which gave me this:
220 mx.google.com ESMTP g31sm26175135rvb.16

If anyone knows how to make an SMTP client with scar please help :p

Lance

2009-08-04 02:49:22

i keep getting this:
HTTP/1.1 405 Method Not Allowed
Emailing User Failed!

also, im not sure if im doing this right.. Im trying to get the script to email me proggies

Report('Script Finished');
SendEmail('yakpwner@gmail.com', Players[CurrentPlayer].Name, GetDebugText, 'yakpwner@gmail.com', Players[CurrentPlayer].Name, 'http://yakpwner.webs.com/')

i dont understand how to setup the function :P could you explain it alittle better to me? and does the website have to be the .php file?

btw i copied and pasted your php script into notepad and then saved it as "email.php" but now its "email.php.txt" =[ how do i make it a php file?

TRiLeZ

2009-08-04 03:10:06

From: lancerawks aka Lance
i keep getting this:
HTTP/1.1 405 Method Not Allowed
Emailing User Failed!

also, im not sure if im doing this right.. Im trying to get the script to email me proggies

Report('Script Finished');
SendEmail('yakpwner@gmail.com', Players[CurrentPlayer].Name, GetDebugText, 'yakpwner@gmail.com', Players[CurrentPlayer].Name, 'http://yakpwner.webs.com/')

i dont understand how to setup the function :P could you explain it alittle better to me? and does the website have to be the .php file?


Ya, the website has to be the .php file.
Im gonna make a vid of how to do this sometime.

Lance

2009-08-04 05:35:28

ok.. and with the Http Method not aloud thing, is that a problem with the php then?

SKy Scripter

2009-08-05 13:24:44

it's in test folders…



program POPTest;

const
POP_SERVER = 'mail.no.lv'; //enter your mail server address here
POP_USER = 'user'; //enter your mailbox user here

var
con1: Integer;
s: string;

procedure WaitForResponseAndRead;
begin
repeat
if(ReadConnectionData(con1, s))then
begin
Writeln(s);
end else
begin
Writeln('Connection error');
Exit;
end;
until(s<>'')or(not IsConnectionOpen(con1));
end;

begin
con1:= OpenConnection(POP_SERVER, 110, 15000);
if(con1 >= 0)then
begin
WaitForResponseAndRead;
SendConnectionData(con1, 'USER ' + POP_USER + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'PASS ' + Readln('Password?') + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'STAT' + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'LIST' + #13#10);
WaitForResponseAndRead;
FreeConnection(con1);
end else
begin
Writeln('Unable to connect');
end;
end.

Heysus

2009-08-05 18:54:20

From: SKy Scripter
it's in test folders…



program POPTest;

const
POP_SERVER = 'mail.no.lv'; //enter your mail server address here
POP_USER = 'user'; //enter your mailbox user here

var
con1: Integer;
s: string;

procedure WaitForResponseAndRead;
begin
repeat
if(ReadConnectionData(con1, s))then
begin
Writeln(s);
end else
begin
Writeln('Connection error');
Exit;
end;
until(s<>'')or(not IsConnectionOpen(con1));
end;

begin
con1:= OpenConnection(POP_SERVER, 110, 15000);
if(con1 >= 0)then
begin
WaitForResponseAndRead;
SendConnectionData(con1, 'USER ' + POP_USER + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'PASS ' + Readln('Password?') + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'STAT' + #13#10);
WaitForResponseAndRead;
SendConnectionData(con1, 'LIST' + #13#10);
WaitForResponseAndRead;
FreeConnection(con1);
end else
begin
Writeln('Unable to connect');
end;
end.



Doesn't POP retrieve mail from your email, not send it?

SKy Scripter

2009-08-06 10:28:16

From: Heysus
Doesn't POP retrieve mail from your email, not send it?


Follow The
SendConnection Data Steps at
http://www.emailaddressmanager.com/tips/mail-settings.html

Seroko

2009-08-12 03:03:53

Procedure WaitForResponse(c : Integer);
var
s : String;
begin
repeat
if (ReadConnectionData(c, s))then
begin
Wait(50);
end else
begin
Writeln('Connection error');
Exit;
end;
until(s<>'')or(not IsConnectionOpen(c));
end;

Procedure SendEmail(smtpserver, frommail, tomail, subject, data : String);
var
c : Integer;
begin
c := OpenConnection(smtpserver, 25, 1000);
WaitForResponse(c);
SendConnectionData(c, 'HELO me' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'MAIL FROM: ' + frommail + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'RCPT TO: <' + tomail + '>' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'DATA' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'Subject: ' + subject + #13#10#13#10);
SendConnectionData(c, data + #13#10);
SendConnectionData(c, '.' + #13#10);
WaitForResponse(c);
end;

Can be an example for SMTP, I use it for my personal scripts since each ISP does different things for SMTP, some block it and require you to use their own etc.

SendEmail('smtp.yourisp.com', 'yourscript@gmail.com', 'seroko@gmail.com', 'Progress Report', 'You earned over 9000 xp.');

Heysus

2009-08-13 02:55:59

From: Seroko
Procedure WaitForResponse(c : Integer);
var
s : String;
begin
repeat
if (ReadConnectionData(c, s))then
begin
Wait(50);
end else
begin
Writeln('Connection error');
Exit;
end;
until(s<>'')or(not IsConnectionOpen(c));
end;

Procedure SendEmail(smtpserver, frommail, tomail, subject, data : String);
var
c : Integer;
begin
c := OpenConnection(smtpserver, 25, 1000);
WaitForResponse(c);
SendConnectionData(c, 'HELO me' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'MAIL FROM: ' + frommail + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'RCPT TO: <' + tomail + '>' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'DATA' + #13#10);
WaitForResponse(c);
SendConnectionData(c, 'Subject: ' + subject + #13#10#13#10);
SendConnectionData(c, data + #13#10);
SendConnectionData(c, '.' + #13#10);
WaitForResponse(c);
end;



Thank You! :D

I got this working and my script can now send text messages to my phone (through an email). I have even been able to use a POP server to send messages back to my script :)

I can send something like "proggy" to my script and it will send back a progress report :p

Edit: I'm just having one problem: After it reads the message i need to delete it so it won't read the same message over and over. But for some reason the message doesn't get deleted until i restart the script.

Edit2: I have no idea what i did but it works now

anonymity

2010-04-28 18:32:19

Would it be possible to attach/add a file (ex: .jpg, .png, .csv, xlsx) in that canned email?

Illkillutill

2010-05-14 00:26:01

Same question here as mentioned above, is it possible?

TRiLeZ

2010-05-14 01:27:47

From: Illkillutill
Same question here as mentioned above, is it possible?


With PascalScript, I doubt it.

marpis

2010-05-14 11:00:11

From: anonymity
Would it be possible to attach/add a file (ex: .jpg, .png, .csv, xlsx) in that canned email?


From: Illkillutill
Same question here as mentioned above, is it possible?


You can turn the bitmap into a string, send the string and when you want to view the pictures translate them into images with scar again :)

anonymity

2010-05-14 16:50:29

From: marpis
You can turn the bitmap into a string, send the string and when you want to view the pictures translate them into images with scar again :)


How about anything other than a picture?

anonymity

2010-06-06 03:47:20

Double post, yea, I know.. But this is a new thought and on a different line of thought.
From: Heysus
Edit: I'm just having one problem: After it reads the message i need to delete it so it won't read the same message over and over. But for some reason the message doesn't get deleted until i restart the script
So, I was on the road today, and I got thinking. I have a signature on my phone for when I send text messages. Well I was thinking, that will be a problem when I text my program back…

*Light bulb goes on* Why not just have my program recognize my signature (which is at the end of all my txts) and "exit; break; or whatever" to dismiss the command after it has been deployed.

marpis

2010-06-11 16:03:49

From: anonymity
How about anything other than a picture?


Why would you want to make it send anything more than pictures and text? o_O

Dgby714

2010-06-11 19:45:20

Looked at this and started playing with it =)

heres my php and simba scripts now >.<

[php]<?php
$DefaultEmail = 'Default@email.com';
$RequiredUserAgent = 'Simba';

if ($_SERVER['HTTP_USER_AGENT'] != $RequiredUserAgent) {
die('ERROR Incorrect UserAgent (' . $_SERVER['HTTP_USER_AGENT'] . ')!');
}

if (isset($_POST['email']) && $_POST['email'] != '') {
$TheEmail[0] = $_POST['email'];
} else {
$TheEmail[0] = $DefaultEmail;
}

if (isset($_POST['subject']) && $_POST['subject'] != '') {
$TheEmail[1] = $_POST['subject'];
} else {
$TheEmail[1] = 'Unknown Subject';
}

if (isset($_POST['message']) && $_POST['message'] != '') {
$TheEmail[2] = $_POST['message'];
} else {
die('ERROR: Missing Message!');
}

if (isset($_POST['name']) && $_POST['name'] != '') {
$TheEmail[3] = 'From: ' . $_POST['name'];
} else {
$TheEmail[3] = 'From: Default';
}

if (isset($_POST['sender']) && $_POST['sender'] != '') {
$TheEmail[3] .= ' <' . $_POST['sender'] . '>';
} else {
$TheEmail[3] .= ' <' . $DefaultEmail . '>';
}

if (@mail($TheEmail[0], $TheEmail[1], $TheEmail[2], $TheEmail[3])) {
echo 'Success!';
} else {
echo 'Unknown Error!';
}
?>[/php]

function SendEmail(FromName, FromEmail, ToEmail, Subject, Msg: string): string;
var
Client: integer;
begin
Client := InitializeHTTPClient(True);
try
ClearPostData(Client);
SetHTTPUserAgent(Client, 'Simba');
AddPostVariable(Client, 'name', FromName);
AddPostVariable(Client, 'sender', FromEmail);
AddPostVariable(Client, 'email', ToEmail);
AddPostVariable(Client, 'subject', Subject);
AddPostVariable(Client, 'message', Msg);
Result := PostHTTPPageEx(Client, 'http://localhost/Blank/mail.php');
finally
FreeHTTPClient(Client);
end;
end;

anonymity

2010-06-18 18:13:09

^ Neato, and thanks for the post.

From: marpis
Why would you want to make it send anything more than pictures and text? o_O
For runescape? I am not quite sure. I am more curious to if it is possible.. add some sort of attachment and when it sends it copies what was 'attached' and sends it.