SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 08/06/2018, 02:24 PM   #1
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,023
Reputation: 134
Default SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS


This is an include that can send emails from your server, directly through a GMAIL account. The great advantage of doing this, is that the emails will NEVER end in the SPAM folder, because they are sent from GMAIL servers, and no email provider blocks them. It uses a simple NodeJS script to handle everything. It's super easy to setup.

You can use this, for example to create email confirmations, forgot password, send ban detais via email, send logs or warnings to administrators, etc.

FUNCTIONS

Code:
SendEmail(name[], to[], subject[], text[], bool:isTemplate = false, templateName[] = "default.html")

EXAMPLE

When using the default.html template (avaliable in the repository), this code:

Code:
SendEmail("It's me", "*************@gmail.com", "This is a subject test with template", "PLAYERNAME:bruxo#PADDRESS:127.0.0.1#DREG:08/06/2018", true);
Will generate this email:




Wiki - How to setup and how to use
Github Repository


I'm not a NodeJS expert, the code CAN be optimized, and I will do that when I'm feeling like doing that.

Last edited by bruxo00; 16/06/2018 at 10:19 AM.
bruxo00 is offline   Reply With Quote
Old 08/06/2018, 03:02 PM   #2
nnahtann
Little Clucker
 
nnahtann's Avatar
 
Join Date: Sep 2017
Location: ml-rp.com
Posts: 44
Reputation: 17
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Very useful! Thanks for releasing!
__________________
nnahtann is offline   Reply With Quote
Old 10/06/2018, 10:42 AM   #3
Verc
Big Clucker
 
Join Date: Apr 2018
Posts: 62
Reputation: 8
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

The response code from the console is "Email 1 sent successfully" yet,there's nothing in my email.
And,this:

PHP Code:
#define SAMPMAILJS_URL "" // IP + PORT of the server running the NodeJS script 
Port is not needed,only the directory where your sampmail.js located.
Verc is offline   Reply With Quote
Old 13/06/2018, 10:44 AM   #4
ByMatt20030
Big Clucker
 
Join Date: Jul 2016
Posts: 76
Reputation: 0
Talking Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Hi!, first of all... congrats, this is incredible.

I have error 400 on response of SendEmail...
My code:
Code:
SendEmail("Mail Test", "***********@hotmail.com", "test title", "does this works? the answer is the same of:  did you see the title? -_-| try number #53816 - year -212 BC"); //i send this on ongamemodeinit.


//sampmailjs.inc:
#define SAMPMAILJS_URL "192.168.0.19:7777" // i tried with 127.0.0.1:7777 but same result...
#define SAMPMAILJS_PASSWORD "*******" // i have a question of this password, this is the gmail account password? or which?

//sampmail.js
var localIP = "192.168.0.19";
var port = 7777;
var httpPassword = "********"; // i have a question of this password, this is the gmail account password? or which?
var ******_Account = "[email protected]";
var ******_ClientID = "**********.apps.******usercontent.com";
var ******_ClientSecret = "***********";
var ******_RefreshToken = "*********";
var detailedDebug = 1;
I'm on Windows 7, executing sampmail.js with Windows Command Tool (cmd.exe located in NodeJS directory and sending execute with command "node sampmail.js") because node.exe send me this error at executing the file:
Code:
node sampmail.js
     ^^^^^^^^

SyntaxError: Unexpected identifier
Have a nice day!

Last edited by ByMatt20030; 13/06/2018 at 12:11 PM.
ByMatt20030 is offline   Reply With Quote
Old 13/06/2018, 12:28 PM   #5
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,023
Reputation: 134
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by Verc View Post
The response code from the console is "Email 1 sent successfully" yet,there's nothing in my email.
And,this:

PHP Code:
#define SAMPMAILJS_URL "" // IP + PORT of the server running the NodeJS script 
Port is not needed,only the directory where your sampmail.js located.
Can you tell me what it shows on the nodejs script console?

Yes, the port is needed. It isn't needed if the script is listening on the default HTTP port (80), otherwise it will not work without the port.
__________________
RELEASES

[INC] SAMPMailJS
[FS] doxIT!
[GM] Paradise City Roleplay
[TOOL] bAnticheat
[TOOL] Logs Checker
[TUTORIAL] Email confirmation system
bruxo00 is offline   Reply With Quote
Old 13/06/2018, 12:36 PM   #6
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,023
Reputation: 134
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by ByMatt20030 View Post
Hi!, first of all... congrats, this is incredible.

I have error 400 on response of SendEmail...
My code:
Code:
SendEmail("Mail Test", "***********@hotmail.com", "test title", "does this works? the answer is the same of:  did you see the title? -_-| try number #53816 - year -212 BC"); //i send this on ongamemodeinit.


//sampmailjs.inc:
#define SAMPMAILJS_URL "192.168.0.19:7777" // i tried with 127.0.0.1:7777 but same result...
#define SAMPMAILJS_PASSWORD "*******" // i have a question of this password, this is the gmail account password? or which?

//sampmail.js
var localIP = "192.168.0.19";
var port = 7777;
var httpPassword = "********"; // i have a question of this password, this is the gmail account password? or which?
var ******_Account = "[email protected]";
var ******_ClientID = "**********.apps.******usercontent.com";
var ******_ClientSecret = "***********";
var ******_RefreshToken = "*********";
var detailedDebug = 1;
I'm on Windows 7, executing sampmail.js with Windows Command Tool (cmd.exe located in NodeJS directory and sending execute with command "node sampmail.js") because node.exe send me this error at executing the file:
Code:
node sampmail.js
     ^^^^^^^^

SyntaxError: Unexpected identifier
Have a nice day!
SAMPMAILJS_PASSWORD - this password must be the same password as httpPassword in the sampmail.js. This is to prevent external users to use the script without your consent, it has nothing to do with your gmail password.

Wich version of NodeJS do you have? Please send the email and tell me what error appears on the NodeJS console. I didn't tested the script on windows, but in theory it should work the same way it works on Linux.
__________________
RELEASES

[INC] SAMPMailJS
[FS] doxIT!
[GM] Paradise City Roleplay
[TOOL] bAnticheat
[TOOL] Logs Checker
[TUTORIAL] Email confirmation system
bruxo00 is offline   Reply With Quote
Old 13/06/2018, 01:27 PM   #7
ByMatt20030
Big Clucker
 
Join Date: Jul 2016
Posts: 76
Reputation: 0
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by bruxo00 View Post
SAMPMAILJS_PASSWORD - this password must be the same password as httpPassword in the sampmail.js. This is to prevent external users to use the script without your consent, it has nothing to do with your gmail password.

Wich version of NodeJS do you have? Please send the email and tell me what error appears on the NodeJS console. I didn't tested the script on windows, but in theory it should work the same way it works on Linux.
Thanks for answering!

At first i try with 8.11.3, then i see you make this work on a newer version so i tried with 10.4.1... but still the same problem.
Error code on console at sending email:
Code:
F:\Users\Administrator\Desktop\SA:MP Server\v0.2.3 w/advanced login portal>node sampmail.js
Server running on http://192.168.0.19:7777/
Client (192.168.0.19) requested /sampmail.js?pw=mypassword&action=sendm
================ SENDING EMAIL ================
De: Mail Test
To: [email protected]
Subject: test
Text: this works, but doesn't finish the email sending
===============================================
[192.168.0.19] -> 400: Error
samp-server.exe error code:
Code:
[SAMPMAILJS] Server returned a response 400
If necesary to post, i use this includes on that code:
Code:
#include <a_samp>
#undef MAX_PLAYERS
#define MAX_PLAYERS 100
#include <crashdetect>
#include <sampmailjs>
#include <YSI_Storage\y_ini>
#include <YSI_Data\y_iterate>
#include <YSI_Coding\y_timers>
#include <YSI_Core\y_utils>
#include <YSI_Server\y_flooding>
#include <djson> //later i'll replace this with y_ini... i'm so lazy don't judge me :P
#include <GM_Hooks> //some personal hooks, not more than 3 or 4 simple functions.
#include <yom_buttons>
#include <samp-dl-compat>
#include <Miles> // Some hooks.
#include <fixes>
#include <sscanf2>
#include <streamer>
#include <Pawn.CMD>
#include <NewMenus> //mselection w/ big interface changes
#include <mSelection>   
#include <progressbar>
#include <faderscreen>
#include <AntiCheat>
#define FOREACH_NO_BOTS
#define FOREACH_NO_ACTORS
#pragma option -d3
And Zeex's Pawn Compiler.

Greetings!
ByMatt20030 is offline   Reply With Quote
Old 13/06/2018, 01:58 PM   #8
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,023
Reputation: 134
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by ByMatt20030 View Post
Thanks for answering!

At first i try with 8.11.3, then i see you make this work on a newer version so i tried with 10.4.1... but still the same problem.
Error code on console at sending email:
Code:
F:\Users\Administrator\Desktop\SA:MP Server\v0.2.3 w/advanced login portal>node sampmail.js
Server running on http://192.168.0.19:7777/
Client (192.168.0.19) requested /sampmail.js?pw=mypassword&action=sendm
================ SENDING EMAIL ================
De: Mail Test
To: [email protected]
Subject: test
Text: this works, but doesn't finish the email sending
===============================================
[192.168.0.19] -> 400: Error
samp-server.exe error code:
Code:
[SAMPMAILJS] Server returned a response 400
If necesary to post, i use this includes on that code:
Code:
#include <a_samp>
#undef MAX_PLAYERS
#define MAX_PLAYERS 100
#include <crashdetect>
#include <sampmailjs>
#include <YSI_Storage\y_ini>
#include <YSI_Data\y_iterate>
#include <YSI_Coding\y_timers>
#include <YSI_Core\y_utils>
#include <YSI_Server\y_flooding>
#include <djson> //later i'll replace this with y_ini... i'm so lazy don't judge me :P
#include <GM_Hooks> //some personal hooks, not more than 3 or 4 simple functions.
#include <yom_buttons>
#include <samp-dl-compat>
#include <Miles> // Some hooks.
#include <fixes>
#include <sscanf2>
#include <streamer>
#include <Pawn.CMD>
#include <NewMenus> //mselection w/ big interface changes
#include <mSelection>   
#include <progressbar>
#include <faderscreen>
#include <AntiCheat>
#define FOREACH_NO_BOTS
#define FOREACH_NO_ACTORS
#pragma option -d3
And Zeex's Pawn Compiler.

Greetings!
Your problem probably is that you probably didn't set up the gmail API correctly. I will do some changes in the future to handle the most basic errors, but for now go to the line 156 of sampmail.js and replace this:

HTML Code:
console.log("[" + req.connection.remoteAddress + "] -> 400: Error");
with this:

HTML Code:
console.log("[" + req.connection.remoteAddress + "] -> 400: Error\n" + err);
And run again and post here the error that will appear. Thanks!
__________________
RELEASES

[INC] SAMPMailJS
[FS] doxIT!
[GM] Paradise City Roleplay
[TOOL] bAnticheat
[TOOL] Logs Checker
[TUTORIAL] Email confirmation system
bruxo00 is offline   Reply With Quote
Old 13/06/2018, 02:36 PM   #9
ByMatt20030
Big Clucker
 
Join Date: Jul 2016
Posts: 76
Reputation: 0
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by bruxo00 View Post
Your problem probably is that you probably didn't set up the gmail API correctly. I will do some changes in the future to handle the most basic errors, but for now go to the line 156 of sampmail.js and replace this:

HTML Code:
console.log("[" + req.connection.remoteAddress + "] -> 400: Error");
with this:

HTML Code:
console.log("[" + req.connection.remoteAddress + "] -> 400: Error\n" + err);
And run again and post here the error that will appear. Thanks!
Ok, i checked the gmail API at least six times and i do the same like this post.
Buy, still not working.

With that code, now i have this console message:
Code:
[192.168.0.19] -> 400: Error  nError: self signed certificate in certificate cha
in
Thanks for support, appreciate it!
ByMatt20030 is offline   Reply With Quote
Old 13/06/2018, 03:39 PM   #10
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,023
Reputation: 134
Default Re: SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS

Quote:
Originally Posted by ByMatt20030 View Post
Ok, i checked the gmail API at least six times and i do the same like this post.
Buy, still not working.

With that code, now i have this console message:
Code:
[192.168.0.19] -> 400: Error  nError: self signed certificate in certificate cha
in
Thanks for support, appreciate it!
Please turn THIS on on the sender account, test it and tell me if it worked.
__________________
RELEASES

[INC] SAMPMailJS
[FS] doxIT!
[GM] Paradise City Roleplay
[TOOL] bAnticheat
[TOOL] Logs Checker
[TUTORIAL] Email confirmation system
bruxo00 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] SAMPMailJS [NodeJS] bruxo00 Lanšamentos/Releases 41 17/06/2018 10:14 PM
Receive, Send and answer to EMails INGAME !!! Trooper[Y] Screenshots and Videos 4 08/04/2011 04:58 AM
Using HTTP to send emails Jochemd Help Archive 3 19/02/2011 11:28 AM
can someone list some GTA HTML templates!?!?! SanMarinoRP Everything and Nothing 4 04/09/2009 09:57 PM


All times are GMT. The time now is 01:25 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.