forked from diogomartino/SAMPMailJS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsampmailjs.inc
More file actions
51 lines (40 loc) · 1.8 KB
/
sampmailjs.inc
File metadata and controls
51 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#if !defined n_sampmailjs_include
#define n_sampmailjs_include
#endif
#include a_http
#include strlib
#define SAMPMAILJS_RESPONSE_OK 200
#define SAMPMAILJS_RESPONSE_FORBIDEN 403
#define SAMPMAILJS_RESPONSE_ERROR 400
#define SAMPMAILJS_RESPONSE_NOTFOUND 404
#define SAMPMAILJS_URL "127.0.0.1:8080" // IP + PORT of the server running the NodeJS script
#define SAMPMAILJS_PASSWORD "changeme" // This password should be the same as the NodeJS script
#define SAMPMAILJS_CONSOLELOG 0 // Log some information on console
#define SAMPMAILJS_MAXPOSTDATA 1024 // Cellsize of the variable that holds the data sent to the script. Lower for small emails, higher for more extense emails
new uniqueID = 0;
forward HandleHTTPResponse(index, response_code, data[]);
public HandleHTTPResponse(index, response_code, data[]) {
uniqueID++;
#if SAMPMAILJS_CONSOLELOG == 1
printf("\n[SAMPMAILJS] Server returned a response %d", response_code);
#endif
if (response_code == SAMPMAILJS_RESPONSE_OK) {
#if SAMPMAILJS_CONSOLELOG == 1
printf("\n[SAMPMAILJS] Email %d sent successfully", uniqueID);
#endif
}
return response_code;
}
stock SendEmail(name[], to[], subject[], text[], bool:isTemplate = false, templateName[] = "default.html") {
new string[128], postData[SAMPMAILJS_MAXPOSTDATA];
if(isTemplate) {
format(string, sizeof string, "%s/sampmail.js?pw=%s&action=sendmtmp", SAMPMAILJS_URL, SAMPMAILJS_PASSWORD);
format(postData, sizeof postData, "%s|%s|%s|%s|%s", name, to, subject, text, templateName);
}
else {
format(string, sizeof string, "%s/sampmail.js?pw=%s&action=sendm", SAMPMAILJS_URL, SAMPMAILJS_PASSWORD);
format(postData, sizeof postData, "%s|%s|%s|%s", name, to, subject, text);
}
utf8encode(postData, postData);
return HTTP(uniqueID, HTTP_POST, string, postData, "HandleHTTPResponse");
}