Need a plugin

Started by MRSK143, Mar 05, 2022, 07:09 PM

Previous topic - Next topic

MRSK143

Hi @Xmair , I hope you are doing well can you plz give me your vcmp email plugin?
@mR_Sk@

Xmair

Don't have it anymore

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

MRSK143

Bruh... then can you make it again or provide its source code plz?
@mR_Sk@

Xmair

Quote from: MRSK143 on Mar 06, 2022, 06:26 AMBruh... then can you make it again or provide its source code plz?
I lost the source code and I don't have any interest or time to spare for VCMP. Sorry.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

habi

#4
I got interested and made a program. I didn't have time to make a 'plugin'.
The following little program sends email from your gmail account, provided you give your email id and password to it. Also you need to give access to unsecure apps from your gmail account by visiting the link in the code below.

You can send email from your gmail account to any account(not restricted to gmail accounts only)

gmail.nut
/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */
/*Credits to: https://forum.vc-mp.org/?topic=6116.msg42113#msg42113 for instructions to write to file
in squirrel*/

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
system("del mail.txt");
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
myfile.writen(c,'b');
}
myfile.close();
local cmd="start curl.exe smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth";
//print(cmd);
system(cmd);
}
Usage:
First load the file by (expecting gmail.nut in the same directory as server.exe)
dofile("gmail.nut");Send message by
SendEmailFromGmailAccount("[email protected]","mypassword","[email protected]","MySubject","Hello sending email from squirrel. Thanks")
I have tested it and it works for me.
Note: To make the program work, you need to have curl atleast on your server directory.
For that visit https://curl.se/windows/ and download curl for 32 bit. After download, open and go to the folder bin and copy "curl.exe", "libcurl.dll" and "curl-ca-bundle.crt" to your server folder.

Additional Info: We have made use of command "start process" in squirrel's system function. So Server will not wait for it to complete, thus possibily avoiding delays or pauses.

Instructions for linux:
Go here: https://github.com/moparisthebest/static-curl/releases/tag/v7.82.0 and download curl-amd64.
Rename it to "curl" and paste in server folder.
Find the following similar line in gmail.nut and change it as it is given below
local cmd="nohup ./curl smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth &>/dev/null &";Do not delete any other lines.
Now, open your terminal and type chmod 777 curl
Then you can run your server by ./mpsvrrel64

MRSK143

Quote from: habi on Mar 06, 2022, 07:07 PMI got interested and made a program. I didn't have time to make a 'plugin'.
The following little program sends email from your gmail account, provided you give your email id and password to it. Also you need to give access to unsecure apps from your gmail account by visiting the link in the code below.

You can send email from your gmail account to any account(not restricted to gmail accounts only)

gmail.nut
/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */
/*Credits to: https://forum.vc-mp.org/?topic=6116.msg42113#msg42113 for instructions to write to file
in squirrel*/

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
system("del mail.txt");
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
myfile.writen(c,'b');
}
myfile.close();
local cmd="start curl.exe smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth";
//print(cmd);
system(cmd);
}
Usage:
First load the file by (expecting gmail.nut in the same directory as server.exe)
dofile("gmail.nut");Send message by
SendEmailFromGmailAccount("[email protected]","mypassword","[email protected],"MySubject","Hello sending email from squirrel. Thanks")
I have tested it and it works for me.
Note: To make the program work, you need to have curl atleast on your server directory.
For that visit https://curl.se/windows/ and download curl for 32 bit. After download, open and go to the folder bin and copy "curl.exe", "libcurl.dll" and "curl-ca-bundle.crt" to your server folder.

Additional Info: We have made use of command "start process" in squirrel's system function. So Server will not wait for it to complete, thus possibily avoiding delays or pauses.

Instructions for linux:
Go here: https://github.com/moparisthebest/static-curl/releases/tag/v7.82.0 and download curl-amd64.
Rename it to "curl" and paste in server folder.
Find the following similar line in gmail.nut and change it as it is given below
local cmd="nohup ./curl smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth &>/dev/null &";Do not delete any other lines.
Now, open your terminal and type chmod 777 curl
Then you can run your server by ./mpsvrrel64

Hi thanks a lot your system works awesome it sent the email less 20 seconds lol its really working, btw are you on discord?
@mR_Sk@

MRSK143

Quote from: habi on Mar 06, 2022, 07:07 PMI got interested and made a program. I didn't have time to make a 'plugin'.
The following little program sends email from your gmail account, provided you give your email id and password to it. Also you need to give access to unsecure apps from your gmail account by visiting the link in the code below.

You can send email from your gmail account to any account(not restricted to gmail accounts only)

gmail.nut
/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */
/*Credits to: https://forum.vc-mp.org/?topic=6116.msg42113#msg42113 for instructions to write to file
in squirrel*/

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
system("del mail.txt");
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
myfile.writen(c,'b');
}
myfile.close();
local cmd="start curl.exe smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth";
//print(cmd);
system(cmd);
}
Usage:
First load the file by (expecting gmail.nut in the same directory as server.exe)
dofile("gmail.nut");Send message by
SendEmailFromGmailAccount("[email protected]","mypassword","[email protected],"MySubject","Hello sending email from squirrel. Thanks")
I have tested it and it works for me.
Note: To make the program work, you need to have curl atleast on your server directory.
For that visit https://curl.se/windows/ and download curl for 32 bit. After download, open and go to the folder bin and copy "curl.exe", "libcurl.dll" and "curl-ca-bundle.crt" to your server folder.

Additional Info: We have made use of command "start process" in squirrel's system function. So Server will not wait for it to complete, thus possibily avoiding delays or pauses.

Instructions for linux:
Go here: https://github.com/moparisthebest/static-curl/releases/tag/v7.82.0 and download curl-amd64.
Rename it to "curl" and paste in server folder.
Find the following similar line in gmail.nut and change it as it is given below
local cmd="nohup ./curl smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth &>/dev/null &";Do not delete any other lines.
Now, open your terminal and type chmod 777 curl
Then you can run your server by ./mpsvrrel64

btw how can i detect that the recipient email doesn't exist
@mR_Sk@

habi

#7
Quotebtw how can i detect that the recipient email doesn't exist
For that you can use regexp ( I just learned )
function IsValidEmailAddress(email)
{
return regexp(@"^[-\w_.]+@[-\w.]+$").match(email);
}

Let me explain.

The ^[-\w_.]+ tells the squirrel that email should begin with and followed by(^ means begin +means repetition)  anycharacter inside the square bracket. So your email can begin with \w (means word. ie a to z or A to Z or 0 to 9) and followed by any  a to z,A-Z,0-9 character or Dot (.), Underscore (_) or Hyphen(-).
The plus symbol + means such characters in the brackets can be repeated any number of times.
Now @ means the email should contain the symbol @
Now the part of the email after @ can contain any word character(\w), Dot(.) or Hyphen(-) which is coded by [-\w.]+
and $ means the email should end with such characters.
Ref: regexp (javascript)
print(IsValidEmailAddress("[email protected]"))
[SCRIPT]  true
print(IsValidEmailAddress("hello#[email protected]"))
[SCRIPT]  false
PS: i am not available on discord

MRSK143

#8
Quote from: habi on Mar 07, 2022, 07:27 AM
Quotebtw how can i detect that the recipient email doesn't exist
For that you can use regexp ( I just learned )
function IsValidEmailAddress(email)
{
return regexp(@"^[-\w_.]+@[-\w.]+$").match(email);
}

Let me explain.

The ^[-\w_.]+ tells the squirrel that email should begin with and followed by(^ means begin +means repetition)  anycharacter inside the square bracket. So your email can begin with \w (means word. ie a to z or A to Z or 0 to 9) and followed by any  a to z,A-Z,0-9 character or Dot (.), Underscore (_) or Hyphen(-).
The plus symbol + means such characters in the brackets can be repeated any number of times.
Now @ means the email should contain the symbol @
Now the part of the email after @ can contain any word character(\w), Dot(.) or Hyphen(-) which is coded by [-\w.]+
and $ means the email should end with such characters.
Ref: regexp (javascript)
print(IsValidEmailAddress("[email protected]"))
[SCRIPT]  true
print(IsValidEmailAddress("hello#[email protected]"))
[SCRIPT]  false
PS: i am not available on discord

Thanks for this but dude I mean that if the email doesn't exist on Google? I tested it and I entered the wrong email and then it send the same email to my Gmail which I used to be sender I want to check if it exist on Google...
@mR_Sk@

habi

#9
Oh my god..
gmail.nut
[noae][noae]/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */

/*function:ReadTextFromFile, Credits: SLC https://forum.vc-mp.org/?topic=6116.msg42113#msg42113*/
function ReadTextFromFile(path)
{
    local f = file(path,"rb"), s = "";

    while (!f.eos())
    {
        s += format(@"%c", f.readn('b'));
    }

    f.close();

    return s;
}

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
system("del mail.txt");
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
 myfile.writen(c,'b');
}
myfile.close();
local cmd="start curl.exe smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth";
//print(cmd);
system(cmd);
}
function IMAPFREE()
{
system("IF EXIST 1.txt del /F 1.txt");
system("IF EXIST output.txt del /F output.txt");
system("IF EXIST query.txt del /F query.txt");
}
function IMAPEXIT()
{
IMAPFREE();
}
function IMAPINIT(from, password)
{
IMAPFREE();
mUID<-0;//the message number. 1 for the first message (very old)
imapEmail<-from;ipass<-password
//updateUID();
generator<-null;
}
function updateUID(...)
{
mUID=0;//Reset UID
local from=imapEmail;local password=ipass;
system("if exist query.txt del query.txt");
local cmd="start curl --url \"imaps://imap.gmail.com:993/INBOX/\" --user "+from+":"+password+" -X \"EXAMINE INBOX\" -o query.txt";
system(cmd);
local flag;
if(vargv.len()==0)
flag=0;
else flag=vargv[0];
qTimer <- NewTimer("mMyTimer", 1000, 11,GetTickCount(),flag);
}
function mMyTimer(oTickcount,flag)
{
local i=IsFileExists("query.txt");
if(!i)
{
if(GetTickCount()>=(oTickcount+10000))
{
print("Fetching UID Failed. Aborting..");
qTimer.Delete();
}
return;
}
local text=ReadTextFromFile("query.txt");
local r=text.find("[UIDNEXT ");
if(!r){
if(GetTickCount()>=(oTickcount+10000))
print("program failed\n");qTimer.Delete();
return;
}
local s=text.find("]",r+1);
local UID=text.slice(r+9,s);
qTimer.Delete();
mUID<-UID;
print("UID = "+mUID);
if(flag==true && generator)
{
try {
print("Sending test email and waiting 15 seconds..");
resume generator;
if(generator.getstatus()!="dead")resume generator;
}catch(e){
print(e);
}
}
}
function IsValidEmailAddress(email,subject,message,param)
{
if(imapEmail==email)
{
print("You cannot use your own email to check");
return;
}
print("Fetching Next UID from Gmail...");
updateUID(true);
generator=__IsValidEmailAddress(email,subject,message,param)
}
function __IsValidEmailAddress(email,subject,message,param)
{
yield _IsValidEmailAddress(email,subject,message,param);
}
function _IsValidEmailAddress(email,subject,message,param)
{
if(mUID==0){print("Program not ready!");return;}
/*if(imapEmail==email)
{
print("You cannot use your own email to check");
return;
}*/
SendEmailFromGmailAccount(imapEmail,ipass,email,subject,message);
//Wait for Email to be send.
qTimer2<-NewTimer("CheckGmailInbox",15000,1,email,param);//10 seconds
}

//Check Gmail Inbox
function CheckGmailInbox(email,p)//email to be tested
{
print("Checking for New mail from google");
ReadEmailFromGmailAccountInbox(imapEmail,ipass,mUID,email,"Address not found",p);
}


//The following function reads Gmail Inbox for message number UID.
//If such a message number exists, it reads the message and checks if the message contains both parameter p1 and p2.
//If true, then it calls onReadSucessMatchFound with parameters p1,p2 and p3.
//Otherwise, it calls onReadSucessMatchNotFound with parameters p1,p2 and p3.
//If such a message number not exists, it calls onReadFromUIDFailed with parameter UID, p1,p2 and p3.
function ReadEmailFromGmailAccountInbox(from, password,UID, p1,p2,p3)//p1=email to be tested, p2="Address not found", p3="player name"
{
//system("del 1.txt");
system("IF EXIST output.txt del /F output.txt");
local cmd="start call_curl curl --url \"imaps://imap.gmail.com:993/INBOX;UID="+UID+"\" --user "+from+":"+password+"  -o output.txt";
//print(cmd);
system(cmd);
qTimer3<-NewTimer("CheckCurlReadEmailFinish",1000,0,GetTickCount(),UID,p1,p2,p3);
}
//The following function is called every second by the caller
//and the function checks if the process started by the caller
//is finished. It aborts after 20 seconds, anyway.
function CheckCurlReadEmailFinish(oTickcount,UID,p1,p2,p3)
{
if(IsFileExists("1.txt"))
{
print("Read Email with UID completed. Checking Success..");
onCurlReadEmailFinish(UID,p1,p2,p3);qTimer3.Delete();}
else if(GetTickCount()>oTickcount+20000)//20 seconds waited. Then abort.
{
qTimer3.Delete();
print("start_curl did not finished after 20 seconds");
}
}
function IsFileExists(filename)
{
local f;
try{f=file(filename,"rb");}
catch(e){return 0;}
return 1;
}
function onCurlReadEmailFinish(UID,p1,p2,p3)
{
qTimer2.Delete();
local i=IsFileExists("output.txt");
if(!i){onReadFromUIDFailed(UID,p1,p2,p3);return;};

//A message arrived. What is it?
local text=ReadTextFromFile("output.txt");

if(text.find(p1) && text.find(p2))
{
onReadSucessMatchFound(p1,p2,p3);
}else onReadSucessMatchNotFound(p1,p2,p3);
return;
}
function onReadFromUIDFailed(UID,p1,p2,p3)
{
if(UID && p2=="Address not found")//This means we are checking for "Address not found"
print("Google's Invalid Email Report not arrived");//No new mail arrived in inbox (UID invalid) //So given email can be correct.
}
function onReadSucessMatchNotFound(p1,p2,p3)
{
if(p2=="Address not found")
print("Could not find Google's report");
}
function onReadSucessMatchFound(p1,p2,p3)
{
if(p2=="Address not found")
{
print("Google reported that email "+p1+" is invalid!");
print("Kick "+p3);
}
}
[/noae][/noae]
call_curl.bat To be placed in server directory
[noae][noae]if exist 1.txt del 1.txt
%*
type NUL > 1.txt
exit
[/noae][/noae]
The function we use is IsValidEmailAddress(email,subject,message,param) where the parameters are
email: email you want to test
subject: subject of the sample email to be send
messge: the message of the sample email to be send
param: Give player Name

So here you go....
[noae][noae]dofile("gmail.nut");
IMAPINIT("[email protected]","yourpassword");
IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email","George");
[/noae][/noae]

This post contains some vital information about reading email using IMAP. I will update it later, if necessary.

[noae][noae]IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email","George");
[SCRIPT]  Fetching Next UID from Gmail...
[SCRIPT]  UID = 8716
[SCRIPT]  Sending test email and waiting 15 seconds..
[SCRIPT]  Checking for New mail from google
[SCRIPT]  Read Email with UID completed. Checking Success..
[SCRIPT]  Google reported that email [email protected] is invalid!
[SCRIPT]  Kick George
[/noae][/noae]

See the function [noae][noae]function onReadSucessMatchFound(p1,p2,p3)
{
if(p2=="Address not found")
{
print("Google reported that email "+p1+" is invalid!");
print("Kick "+p3);
}
}
[/noae][/noae] in gmail.nut

You can view ReadEmailFromGmailAccountInbox documentation for reading an email from gmail account.

Ah, a flowchart i made yesterday,


The time we specified between sending email and checking for gmail report is 15 seconds. Adjust if necessary.

MRSK143

Quote from: habi on Mar 08, 2022, 08:01 AMOh my god..
gmail.nut
[noae][noae][noae]/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */

/*function:ReadTextFromFile, Credits: SLC https://forum.vc-mp.org/?topic=6116.msg42113#msg42113*/
function ReadTextFromFile(path)
{
    local f = file(path,"rb"), s = "";

    while (!f.eos())
    {
        s += format(@"%c", f.readn('b'));
    }

    f.close();

    return s;
}

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
system("del mail.txt");
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
 myfile.writen(c,'b');
}
myfile.close();
local cmd="start curl.exe smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth";
//print(cmd);
system(cmd);
}
function IMAPFREE()
{
system("IF EXIST 1.txt del /F 1.txt");
system("IF EXIST output.txt del /F output.txt");
system("IF EXIST query.txt del /F query.txt");
}
function IMAPEXIT()
{
IMAPFREE();
}
function IMAPINIT(from, password)
{
IMAPFREE();
mUID<-0;//the message number. 1 for the first message (very old)
imapEmail<-from;ipass<-password
//updateUID();
generator<-null;
}
function updateUID(...)
{
mUID=0;//Reset UID
local from=imapEmail;local password=ipass;
system("if exist query.txt del query.txt");
local cmd="start curl --url \"imaps://imap.gmail.com:993/INBOX/\" --user "+from+":"+password+" -X \"EXAMINE INBOX\" -o query.txt";
system(cmd);
local flag;
if(vargv.len()==0)
flag=0;
else flag=vargv[0];
qTimer <- NewTimer("mMyTimer", 1000, 11,GetTickCount(),flag);
}
function mMyTimer(oTickcount,flag)
{
local i=IsFileExists("query.txt");
if(!i)
{
if(GetTickCount()>=(oTickcount+10000))
{
print("Fetching UID Failed. Aborting..");
qTimer.Delete();
}
return;
}
local text=ReadTextFromFile("query.txt");
local r=text.find("[UIDNEXT ");
if(!r){
if(GetTickCount()>=(oTickcount+10000))
print("program failed\n");qTimer.Delete();
return;
}
local s=text.find("]",r+1);
local UID=text.slice(r+9,s);
qTimer.Delete();
mUID<-UID;
print("UID = "+mUID);
if(flag==true && generator)
{
try {
print("Sending test email and waiting 15 seconds..");
resume generator;
if(generator.getstatus()!="dead")resume generator;
}catch(e){
print(e);
}
}
}
function IsValidEmailAddress(email,subject,message,param)
{
if(imapEmail==email)
{
print("You cannot use your own email to check");
return;
}
print("Fetching Next UID from Gmail...");
updateUID(true);
generator=__IsValidEmailAddress(email,subject,message,param)
}
function __IsValidEmailAddress(email,subject,message,param)
{
yield _IsValidEmailAddress(email,subject,message,param);
}
function _IsValidEmailAddress(email,subject,message,param)
{
if(mUID==0){print("Program not ready!");return;}
/*if(imapEmail==email)
{
print("You cannot use your own email to check");
return;
}*/
SendEmailFromGmailAccount(imapEmail,ipass,email,subject,message);
//Wait for Email to be send.
qTimer2<-NewTimer("CheckGmailInbox",15000,1,email,param);//10 seconds
}

//Check Gmail Inbox
function CheckGmailInbox(email,p)//email to be tested
{
print("Checking for New mail from google");
ReadEmailFromGmailAccountInbox(imapEmail,ipass,mUID,email,"Address not found",p);
}


//The following function reads Gmail Inbox for message number UID.
//If such a message number exists, it reads the message and checks if the message contains both parameter p1 and p2.
//If true, then it calls onReadSucessMatchFound with parameters p1,p2 and p3.
//Otherwise, it calls onReadSucessMatchNotFound with parameters p1,p2 and p3.
//If such a message number not exists, it calls onReadFromUIDFailed with parameter UID, p1,p2 and p3.
function ReadEmailFromGmailAccountInbox(from, password,UID, p1,p2,p3)//p1=email to be tested, p2="Address not found", p3="player name"
{
//system("del 1.txt");
system("IF EXIST output.txt del /F output.txt");
local cmd="start call_curl curl --url \"imaps://imap.gmail.com:993/INBOX;UID="+UID+"\" --user "+from+":"+password+"  -o output.txt";
//print(cmd);
system(cmd);
qTimer3<-NewTimer("CheckCurlReadEmailFinish",1000,0,GetTickCount(),UID,p1,p2,p3);
}
//The following function is called every second by the caller
//and the function checks if the process started by the caller
//is finished. It aborts after 20 seconds, anyway.
function CheckCurlReadEmailFinish(oTickcount,UID,p1,p2,p3)
{
if(IsFileExists("1.txt"))
{
print("Read Email with UID completed. Checking Success..");
onCurlReadEmailFinish(UID,p1,p2,p3);qTimer3.Delete();}
else if(GetTickCount()>oTickcount+20000)//20 seconds waited. Then abort.
{
qTimer3.Delete();
print("start_curl did not finished after 20 seconds");
}
}
function IsFileExists(filename)
{
local f;
try{f=file(filename,"rb");}
catch(e){return 0;}
return 1;
}
function onCurlReadEmailFinish(UID,p1,p2,p3)
{
qTimer2.Delete();
local i=IsFileExists("output.txt");
if(!i){onReadFromUIDFailed(UID,p1,p2,p3);return;};

//A message arrived. What is it?
local text=ReadTextFromFile("output.txt");

if(text.find(p1) && text.find(p2))
{
onReadSucessMatchFound(p1,p2,p3);
}else onReadSucessMatchNotFound(p1,p2,p3);
return;
}
function onReadFromUIDFailed(UID,p1,p2,p3)
{
if(UID && p2=="Address not found")//This means we are checking for "Address not found"
print("Google's Invalid Email Report not arrived");//No new mail arrived in inbox (UID invalid) //So given email can be correct.
}
function onReadSucessMatchNotFound(p1,p2,p3)
{
if(p2=="Address not found")
print("Could not find Google's report");
}
function onReadSucessMatchFound(p1,p2,p3)
{
if(p2=="Address not found")
{
print("Google reported that email "+p1+" is invalid!");
print("Kick "+p3);
}
}
[/noae][/noae][/noae]
call_curl.bat To be placed in server directory
[noae][noae][noae]if exist 1.txt del 1.txt
%*
type NUL > 1.txt
exit
[/noae][/noae][/noae]
The function we use is IsValidEmailAddress(email,subject,message,param) where the parameters are
email: email you want to test
subject: subject of the sample email to be send
messge: the message of the sample email to be send
param: Give player Name

So here you go....
[noae][noae][noae]dofile("gmail.nut");
IMAPINIT("[email protected]","yourpassword");
IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email","George");
[/noae][/noae][/noae]

This post contains some vital information about reading email using IMAP. I will update it later, if necessary.

[noae][noae][noae]IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email","George");
[SCRIPT]  Fetching Next UID from Gmail...
[SCRIPT]  UID = 8716
[SCRIPT]  Sending test email and waiting 15 seconds..
[SCRIPT]  Checking for New mail from google
[SCRIPT]  Read Email with UID completed. Checking Success..
[SCRIPT]  Google reported that email [email protected] is invalid!
[SCRIPT]  Kick George
[/noae][/noae][/noae]

See the function [noae][noae][noae]function onReadSucessMatchFound(p1,p2,p3)
{
if(p2=="Address not found")
{
print("Google reported that email "+p1+" is invalid!");
print("Kick "+p3);
}
}
[/noae][/noae][/noae] in gmail.nut

You can view ReadEmailFromGmailAccountInbox documentation for reading an email from gmail account.

Ah, a flowchart i made yesterday,


The time we specified between sending email and checking for gmail report is 15 seconds. Adjust if necessary.

i have sent you a pm in forums profile but you haven't respond yet
@mR_Sk@

habi


MRSK143

Hi habi i got this error in my system can you check my gmail.nut i just modify it a little bit i have sent you the file in Forums pm

[SCRIPT] Fetching Next UID from Gmail...
sh: 1: Syntax error: end of file unexpected (expecting "then")
sh: 1: start: not found
[SCRIPT] Fetching UID Failed. Aborting..
[SCRIPT] Fetching Next UID from Gmail...
sh: 1: Syntax error: end of file unexpected (expecting "then")
sh: 1: start: not found
[SCRIPT] Fetching UID Failed. Aborting..
[SCRIPT] Fetching Next UID from Gmail...
sh: 1: Syntax error: end of file unexpected (expecting "then")
sh: 1: start: not found
@mR_Sk@

habi

That was because, the second version we made above(i.e. reading email with imap) was not made usable for linux.
For linux, the code goes here. (Working, i tested it)
gmail_linux.nut
[noae]/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */

/*function:ReadTextFromFile, Credits: SLC https://forum.vc-mp.org/?topic=6116.msg42113#msg42113*/
function ReadTextFromFile(path)
{
    local f = file(path,"rb"), s = "";

    while (!f.eos())
    {
        s += format(@"%c", f.readn('b'));
    }

    f.close();

    return s;
}

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
delete_file("mail.txt")
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
 myfile.writen(c,'b');
}
myfile.close();
local cmd="nohup ./curl smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth &>/dev/null &";
//print(cmd);
system(cmd);
}
function delete_file(file)
{
local cmd="./delfile "+file;
system(cmd);
}
function IMAPFREE()
{
delete_file("1.txt");
delete_file("output.txt");
delete_file("query.txt");
}
function IMAPEXIT()
{
IMAPFREE();
}
function IMAPINIT(from, password)
{
IMAPFREE();
mUID<-0;//the message number. 1 for the first message (very old)
imapEmail<-from;ipass<-password
//updateUID();
generator<-null;
}

function updateUID(...)
{
mUID=0;//Reset UID
local from=imapEmail;local password=ipass;
delete_file("query.txt");
local cmd="nohup ./curl --url imaps://imap.gmail.com:993/INBOX/ -u "+from+":"+password+ " -X \"EXAMINE INBOX\" -o query.txt &>/dev/null &";
system(cmd);
local flag;
if(vargv.len()==0)
 flag=0;
else flag=vargv[0];
qTimer <- NewTimer("mMyTimer", 1000, 11,GetTickCount(),flag);
}
function mMyTimer(oTickcount,flag)
{
 local i=IsFileExists("query.txt");
 if(!i)
 {
  if(GetTickCount()>=(oTickcount+10000))
  {
   print("Fetching UID Failed. Aborting..");
   qTimer.Delete();
  }
  return;
 }
 local text=ReadTextFromFile("query.txt");
 local r=text.find("[UIDNEXT ");
 if(!r){
 if(GetTickCount()>=(oTickcount+10000))
  print("program failed\n");qTimer.Delete();
 return;
 }
 local s=text.find("]",r+1);
 local UID=text.slice(r+9,s);
 qTimer.Delete();
 mUID<-UID;
 print("UID = "+mUID);
 if(flag==true && generator)
 {
  try {
   print("Sending test email and waiting 15 seconds..");
   resume generator;
   if(generator.getstatus()!="dead")resume generator;
  }catch(e){
   print(e);
  }
 }
}
function IsValidEmailAddress(email,subject,message,param)
{
 if(imapEmail==email)
 {
  print("You cannot use your own email to check");
  return;
 }
 print("Fetching Next UID from Gmail...");
 updateUID(true);
 generator=__IsValidEmailAddress(email,subject,message,param)
}
function __IsValidEmailAddress(email,subject,message,param)
{
 yield _IsValidEmailAddress(email,subject,message,param);
}
function _IsValidEmailAddress(email,subject,message,param)
{
 if(mUID==0){print("Program not ready!");return;}
 /*if(imapEmail==email)
 {
  print("You cannot use your own email to check");
  return;
 }*/
 SendEmailFromGmailAccount(imapEmail,ipass,email,subject,message);
 //Wait for Email to be send.
 qTimer2<-NewTimer("CheckGmailInbox",15000,1,email,param);//10 seconds
}

//Check Gmail Inbox
function CheckGmailInbox(email,p)//email to be tested
{
 print("Checking for New mail from google");
 ReadEmailFromGmailAccountInbox(imapEmail,ipass,mUID,email,"Address not found",p);
}


//The following function reads Gmail Inbox for message number UID.
//If such a message number exists, it reads the message and checks if the message contains both parameter p1 and p2.
//If true, then it calls onReadSucessMatchFound with parameters p1,p2 and p3.
//Otherwise, it calls onReadSucessMatchNotFound with parameters p1,p2 and p3.
//If such a message number not exists, it calls onReadFromUIDFailed with parameter UID, p1,p2 and p3.
function ReadEmailFromGmailAccountInbox(from, password,UID, p1,p2,p3)//p1=email to be tested, p2="Address not found", p3="player name"
{
delete_file("output.txt");
local cmd="nohup ./call_curl curl --url \"imaps://imap.gmail.com:993/INBOX;UID="+UID+"\" --user "+from+":"+password+"  -o output.txt &>/dev/null &";
//print(cmd);
system(cmd);
qTimer3<-NewTimer("CheckCurlReadEmailFinish",1000,0,GetTickCount(),UID,p1,p2,p3);
}
//The following function is called every second by the caller
//and the function checks if the process started by the caller
//is finished. It aborts after 20 seconds, anyway.
function CheckCurlReadEmailFinish(oTickcount,UID,p1,p2,p3)
{
 if(IsFileExists("1.txt"))
 {
  print("Read Email with UID completed. Checking Success..");
  onCurlReadEmailFinish(UID,p1,p2,p3);qTimer3.Delete();}
 else if(GetTickCount()>oTickcount+20000)//20 seconds waited. Then abort.
 {
  qTimer3.Delete();
  print("call_curl did not finished after 20 seconds");
 }
}
function IsFileExists(filename)
{
 local f;
 try{f=file(filename,"rb");}
 catch(e){return 0;}
 return 1;
}
function onCurlReadEmailFinish(UID,p1,p2,p3)
{
 qTimer2.Delete();
 local i=IsFileExists("output.txt");
 if(!i){onReadFromUIDFailed(UID,p1,p2,p3);return;};
 
 //A message arrived. What is it?
 local text=ReadTextFromFile("output.txt");
 
 if(text.find(p1) && text.find(p2))
 {
  onReadSucessMatchFound(p1,p2,p3);
 }else onReadSucessMatchNotFound(p1,p2,p3);
 return; 
}
function onReadFromUIDFailed(UID,p1,p2,p3)
{
 if(UID && p2=="Address not found")//This means we are checking for "Address not found"
  print("Google's Invalid Email Report not arrived");//No new mail arrived in inbox (UID invalid) //So given email can be correct.
}
function onReadSucessMatchFound(p1,p2,p3)
{
 if(p2=="Address not found")
  {
   print("Google reported that email "+p1+" is invalid!");
   local idx=[0];
   local plrid=strtok2(p3,idx);
   local s=strtok2(p3,idx);
   if(s=="Register_Account")
    print("Kicking "+plrid+" while registering an account");
  }
}
function onReadSucessMatchFound(p1,p2,p3)
{
 if(p2=="Address not found")
  {
   print("Google reported that email "+p1+" is invalid!");
   print("Kick "+p3);
  }
}
/*strtok2 modified from Zeex strtok function sa-mp*/
function strtok2(string,array)
{
 local index=array[0];
 local length=string.len();
 /* Skip the leading white space */
 while(index<length && string[index]<=' ')
  index++;
 local result="";
 local offset = index;
 while( index < length && string[index] > ' ' && index-offset < 20-1)
 {
  result+=string.slice(index,index+1);
  index++;
 }
 array[0]=index;
 return result;
}
[/noae]

On server folder, you need to have
delfile
[noae]#!/bin/bash
FILE=$1; if [[ -f "$FILE" ]]; then rm "$FILE"; fi;
[/noae]
call_curl
[noae]#!/bin/bash
FILE=1.txt;if [[ -f $FILE ]]; then rm $FILE; fi
$@
>1.txt
exit
[/noae]

The above two files should have unix type line endings. I use notepad++ and there is an option Windows(CR LF) in bottom. Right click and select UNIX(LF). Otherwise it throw error on squirrel.
Note that the two files also do not have extensions like .txt or anything.
One last thing is that you have to give chmod 777 delfile and chmod 777 call_curl

So if you install these files on server folder, then you are ready to go
dofile("gmail_linux.nut");
IMAPINIT("[email protected]","your_password");
local password="xyz"; //Player account password on your system.
IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email",5+" "+"Register_Account"+" "+password);//Replace 5 by player ID.

PS: Ah make those changes to the functions onReadFromUIDFailed(UID,p1,p2,p3), onReadSucessMatchNotFound(p1,p2,p3), onReadSucessMatchFound(p1,p2,p3) and add functions onInvalidEmailNotDetected, AllowPlayerToRegister which were customized for the need you mentioned.

ciao

MRSK143

Quote from: habi on Mar 13, 2022, 09:23 AMThat was because, the second version we made above(i.e. reading email with imap) was not made usable for linux.
For linux, the code goes here. (Working, i tested it)
gmail_linux.nut
[noae][noae]/*First you need to go here and allow unsecure apps
https://www.google.com/settings/security/lesssecureapps */

/*function:ReadTextFromFile, Credits: SLC https://forum.vc-mp.org/?topic=6116.msg42113#msg42113*/
function ReadTextFromFile(path)
{
    local f = file(path,"rb"), s = "";

    while (!f.eos())
    {
        s += format(@"%c", f.readn('b'));
    }

    f.close();

    return s;
}

function SendEmailFromGmailAccount(from,password,to,subject,message)
{
delete_file("mail.txt")
local myfile = file("mail.txt","wb+");
myfile.seek(0,'e');
local text="From: <"+from+">\r\nTo: <"+to+">\r\nSubject: "+subject+"\r\n\r\n"+message+"\r\n";
foreach(c in text)
{
 myfile.writen(c,'b');
}
myfile.close();
local cmd="nohup ./curl smtps://smtp.gmail.com:465 -v --mail-from "+from+" --mail-rcpt "+to+" --ssl -u "+from+":"+password+" -T "+"mail.txt"+" -k --anyauth &>/dev/null &";
//print(cmd);
system(cmd);
}
function delete_file(file)
{
local cmd="./delfile "+file;
system(cmd);
}
function IMAPFREE()
{
delete_file("1.txt");
delete_file("output.txt");
delete_file("query.txt");
}
function IMAPEXIT()
{
IMAPFREE();
}
function IMAPINIT(from, password)
{
IMAPFREE();
mUID<-0;//the message number. 1 for the first message (very old)
imapEmail<-from;ipass<-password
//updateUID();
generator<-null;
}

function updateUID(...)
{
mUID=0;//Reset UID
local from=imapEmail;local password=ipass;
delete_file("query.txt");
local cmd="nohup ./curl --url imaps://imap.gmail.com:993/INBOX/ -u "+from+":"+password+ " -X \"EXAMINE INBOX\" -o query.txt &>/dev/null &";
system(cmd);
local flag;
if(vargv.len()==0)
 flag=0;
else flag=vargv[0];
qTimer <- NewTimer("mMyTimer", 1000, 11,GetTickCount(),flag);
}
function mMyTimer(oTickcount,flag)
{
 local i=IsFileExists("query.txt");
 if(!i)
 {
  if(GetTickCount()>=(oTickcount+10000))
  {
   print("Fetching UID Failed. Aborting..");
   qTimer.Delete();
  }
  return;
 }
 local text=ReadTextFromFile("query.txt");
 local r=text.find("[UIDNEXT ");
 if(!r){
 if(GetTickCount()>=(oTickcount+10000))
  print("program failed\n");qTimer.Delete();
 return;
 }
 local s=text.find("]",r+1);
 local UID=text.slice(r+9,s);
 qTimer.Delete();
 mUID<-UID;
 print("UID = "+mUID);
 if(flag==true && generator)
 {
  try {
   print("Sending test email and waiting 15 seconds..");
   resume generator;
   if(generator.getstatus()!="dead")resume generator;
  }catch(e){
   print(e);
  }
 }
}
function IsValidEmailAddress(email,subject,message,param)
{
 if(imapEmail==email)
 {
  print("You cannot use your own email to check");
  return;
 }
 print("Fetching Next UID from Gmail...");
 updateUID(true);
 generator=__IsValidEmailAddress(email,subject,message,param)
}
function __IsValidEmailAddress(email,subject,message,param)
{
 yield _IsValidEmailAddress(email,subject,message,param);
}
function _IsValidEmailAddress(email,subject,message,param)
{
 if(mUID==0){print("Program not ready!");return;}
 /*if(imapEmail==email)
 {
  print("You cannot use your own email to check");
  return;
 }*/
 SendEmailFromGmailAccount(imapEmail,ipass,email,subject,message);
 //Wait for Email to be send.
 qTimer2<-NewTimer("CheckGmailInbox",15000,1,email,param);//10 seconds
}

//Check Gmail Inbox
function CheckGmailInbox(email,p)//email to be tested
{
 print("Checking for New mail from google");
 ReadEmailFromGmailAccountInbox(imapEmail,ipass,mUID,email,"Address not found",p);
}


//The following function reads Gmail Inbox for message number UID.
//If such a message number exists, it reads the message and checks if the message contains both parameter p1 and p2.
//If true, then it calls onReadSucessMatchFound with parameters p1,p2 and p3.
//Otherwise, it calls onReadSucessMatchNotFound with parameters p1,p2 and p3.
//If such a message number not exists, it calls onReadFromUIDFailed with parameter UID, p1,p2 and p3.
function ReadEmailFromGmailAccountInbox(from, password,UID, p1,p2,p3)//p1=email to be tested, p2="Address not found", p3="player name"
{
delete_file("output.txt");
local cmd="nohup ./call_curl curl --url \"imaps://imap.gmail.com:993/INBOX;UID="+UID+"\" --user "+from+":"+password+"  -o output.txt &>/dev/null &";
//print(cmd);
system(cmd);
qTimer3<-NewTimer("CheckCurlReadEmailFinish",1000,0,GetTickCount(),UID,p1,p2,p3);
}
//The following function is called every second by the caller
//and the function checks if the process started by the caller
//is finished. It aborts after 20 seconds, anyway.
function CheckCurlReadEmailFinish(oTickcount,UID,p1,p2,p3)
{
 if(IsFileExists("1.txt"))
 {
  print("Read Email with UID completed. Checking Success..");
  onCurlReadEmailFinish(UID,p1,p2,p3);qTimer3.Delete();}
 else if(GetTickCount()>oTickcount+20000)//20 seconds waited. Then abort.
 {
  qTimer3.Delete();
  print("call_curl did not finished after 20 seconds");
 }
}
function IsFileExists(filename)
{
 local f;
 try{f=file(filename,"rb");}
 catch(e){return 0;}
 return 1;
}
function onCurlReadEmailFinish(UID,p1,p2,p3)
{
 qTimer2.Delete();
 local i=IsFileExists("output.txt");
 if(!i){onReadFromUIDFailed(UID,p1,p2,p3);return;};
 
 //A message arrived. What is it?
 local text=ReadTextFromFile("output.txt");
 
 if(text.find(p1) && text.find(p2))
 {
  onReadSucessMatchFound(p1,p2,p3);
 }else onReadSucessMatchNotFound(p1,p2,p3);
 return; 
}
function onReadFromUIDFailed(UID,p1,p2,p3)
{
 if(UID && p2=="Address not found")//This means we are checking for "Address not found"
  print("Google's Invalid Email Report not arrived");//No new mail arrived in inbox (UID invalid) //So given email can be correct.
}
function onReadSucessMatchFound(p1,p2,p3)
{
 if(p2=="Address not found")
  {
   print("Google reported that email "+p1+" is invalid!");
   local idx=[0];
   local plrid=strtok2(p3,idx);
   local s=strtok2(p3,idx);
   if(s=="Register_Account")
    print("Kicking "+plrid+" while registering an account");
  }
}
function onReadSucessMatchFound(p1,p2,p3)
{
 if(p2=="Address not found")
  {
   print("Google reported that email "+p1+" is invalid!");
   print("Kick "+p3);
  }
}
/*strtok2 modified from Zeex strtok function sa-mp*/
function strtok2(string,array)
{
 local index=array[0];
 local length=string.len();
 /* Skip the leading white space */
 while(index<length && string[index]<=' ')
  index++;
 local result="";
 local offset = index;
 while( index < length && string[index] > ' ' && index-offset < 20-1)
 {
  result+=string.slice(index,index+1);
  index++;
 }
 array[0]=index;
 return result;
}
[/noae][/noae]

On server folder, you need to have
delfile
[noae][noae]#!/bin/bash
FILE=$1; if [[ -f "$FILE" ]]; then rm "$FILE"; fi;
[/noae][/noae]
call_curl
[noae][noae]#!/bin/bash
FILE=1.txt;if [[ -f $FILE ]]; then rm $FILE; fi
$@
>1.txt
exit
[/noae][/noae]

The above two files should have unix type line endings. I use notepad++ and there is an option Windows(CR LF) in bottom. Right click and select UNIX(LF). Otherwise it throw error on squirrel.
Note that the two files also do not have extensions like .txt or anything.
One last thing is that you have to give chmod 777 delfile and chmod 777 call_curl

So if you install these files on server folder, then you are ready to go
dofile("gmail_linux.nut");
IMAPINIT("[email protected]","your_password");
local password="xyz"; //Player account password on your system.
IsValidEmailAddress("[email protected]","Welcome","This is send to verify your email",5+" "+"Register_Account"+" "+password);//Replace 5 by player ID.

PS: Ah make those changes to the functions onReadFromUIDFailed(UID,p1,p2,p3), onReadSucessMatchNotFound(p1,p2,p3), onReadSucessMatchFound(p1,p2,p3) and add functions onInvalidEmailNotDetected, AllowPlayerToRegister which were customized for the need you mentioned.

ciao

Hi, i hope you are doin well, buddy i got those errors :/ it asked that the delfile and call_curl doesn't exist in panel but i have it also i have set its permit to 777

[SCRIPT] Fetching Next UID from Gmail...
sh: 1: ./delfile: not found
nohup: appending output to 'nohup.out'
[SCRIPT] UID = 13
[SCRIPT] Sending test email and waiting 15 seconds..
sh: 1: ./delfile: not found
nohup: appending output to 'nohup.out'
[SCRIPT] Checking for New mail from google
sh: 1: ./delfile: not found
nohup: appending output to 'nohup.out'
nohup: failed to run command './call_curl': No such file or directory
[SCRIPT] call_curl did not finished after 20 seconds

@mR_Sk@