[Include] SAMPMailJS | Send Emails Easily | HTML |Templates | NodeJS
#1

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

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

When using the default.html template (avaliable in the repository), this 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.
Reply
#2

Very useful! Thanks for releasing!
Reply
#3

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

PHP код:
#define SAMPMAILJS_URL "" // IP + PORT of the server running the NodeJS script 
Port is not needed,only the directory where your sampmail.js located.
Reply
#4

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

I have error 400 on response of SendEmail...
My 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 = "mymail@gmail.com";
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:
Код:
node sampmail.js
     ^^^^^^^^

SyntaxError: Unexpected identifier
Have a nice day!
Reply
#5

Quote:
Originally Posted by Verc
Посмотреть сообщение
The response code from the console is "Email 1 sent successfully" yet,there's nothing in my email.
And,this:

PHP код:
#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.
Reply
#6

Quote:
Originally Posted by ByMatt20030
Посмотреть сообщение
Hi!, first of all... congrats, this is incredible.

I have error 400 on response of SendEmail...
My 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 = "mymail@gmail.com";
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:
Код:
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.
Reply
#7

Quote:
Originally Posted by bruxo00
Посмотреть сообщение
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:
Код:
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/nl67417e09ee584...3332Client (192.168.0.19) requested /sampmail.js?pw=mypassword&action=sendm
================ SENDING EMAIL ================
De: Mail Test
To: myemail@hotmail.com
Subject: test
Text: this works, but doesn't finish the email sending
===============================================
[192.168.0.19] -> 400: Error
samp-server.exe error code:
Код:
[SAMPMAILJS] Server returned a response 400
If necesary to post, i use this includes on that 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!
Reply
#8

Quote:
Originally Posted by bruxo00
Посмотреть сообщение
Please turn THIS on on the sender account, test it and tell me if it worked.
Nope, still same error ;(
Reply
#9

Quote:
Originally Posted by ByMatt20030
Посмотреть сообщение
Nope, still same error ;(
I've made some changes to the code, download the new .js version from github and try again and let me know. Thanks!
Reply
#10

Quote:
Originally Posted by bruxo00
Посмотреть сообщение
I've made some changes to the code, download the new .js version from github and try again and let me know. Thanks!
Now it works perfectly!

Thanks for the support, have a nice day
Reply
#11

Quote:
Originally Posted by ByMatt20030
Посмотреть сообщение
Now it works perfectly!

Thanks for the support, have a nice day
No problem, glad it worked! Thanks!
Reply
#12

It should work if I put my sampmail.js file ij my vps and I'm testing them in my windows right?
Reply
#13

Quote:
Originally Posted by Verc
Посмотреть сообщение
It should work if I put my sampmail.js file ij my vps and I'm testing them in my windows right?
Yes it should.
Reply
#14

It still doesnt work.

And,I don't understand what to define in the url.
#define SAMPMAILJS_URL "172.xx.xx.xx:8080"
what did I do wrong?I put sampmail.js in /root/
404 is the response code I got.

My configs:
PHP код:
var localIP "127.0.0.1";
var 
port 8080;
var 
httpPassword "1234";
var ******
_Account "kxxxx@gmail.com";
var ******
_ClientID "8xxxx.apps.******usercontent.com";
var ******
_ClientSecret "xxxx";
var ******
_RefreshToken "xxxxxxxxxxxx"
PHP код:
#define SAMPMAILJS_URL "172.xxx.xxx.xxx:8080" // IP + PORT of the server running the NodeJS script
#define SAMPMAILJS_PASSWORD "1234" // This password should be the same as the NodeJS script
#define SAMPMAILJS_CONSOLELOG 1 // Log some information on console
#define SAMPMAILJS_MAXPOSTDATA 2048 // Cellsize of the variable that holds the data sent to the script. Lower for small emails, higher for more extense emails 
the URL is my VPS IP.
Reply
#15

Your localIP is wrong, you can't use 127.0.0.1, it will only listen to the localhost and will not accept external connections. Put your VPS external IP in the localIp variable and try again.
Reply
#16

it still doesn't work,do I have to move my sampmail.js file? It's currently at /root/
Reply
#17

This is a very useful include. Also, edit "trough" to "through".
Reply
#18

Quote:
Originally Posted by Verc
Посмотреть сообщение
it still doesn't work,do I have to move my sampmail.js file? It's currently at /root/
Why doesn't it work? The script doesn't start? If you try to reach it trough your browser, does it work? Note that you need to have the port you use opened in order to work.


Quote:
Originally Posted by cuber
Посмотреть сообщение
This is a very useful include. Also, edit "trough" to "through".
Oh, thanks
Reply
#19

Yes,my browser says incorrect request and the console says:
PHP код:
root@localhost:~# node sampmail.js
Server running on http://172.xxx.xx.xx:8080/
Client (114.4.xxx.xxxrequested /
[
114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxxrequested /favicon.ico
[114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxx requested /favicon.ico
[114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxxrequested /sampmail.js
[114.4.xxx.xxx] -> 404Action inexistente 
EDIT:It worked! Thank you!
Reply
#20

Quote:
Originally Posted by Verc
Посмотреть сообщение
Yes,my browser says incorrect request and the console says:
PHP код:
root@localhost:~# node sampmail.js
Server running on http://172.xxx.xx.xx:8080/
Client (114.4.xxx.xxxrequested /
[
114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxxrequested /favicon.ico
[114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxx requested /favicon.ico
[114.4.xxx.xxx] -> 404Action inexistente
Client 
(114.4.xxx.xxxrequested /sampmail.js
[114.4.xxx.xxx] -> 404Action inexistente 
EDIT:It worked! Thank you!
Nice
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)