@@ -12,6 +12,7 @@ import TestingAPI from "./api/Testing";
12
12
import ContactsBaseAPI from "./api/Contacts" ;
13
13
import ContactListsBaseAPI from "./api/ContactLists" ;
14
14
import TemplatesBaseAPI from "./api/Templates" ;
15
+ import SuppressionsBaseAPI from "./api/Suppressions" ;
15
16
16
17
import CONFIG from "../config" ;
17
18
@@ -22,16 +23,15 @@ import {
22
23
BatchSendResponse ,
23
24
BatchSendRequest ,
24
25
} from "../types/mailtrap" ;
25
- import SuppressionsBaseAPI from "./api/Suppressions" ;
26
26
27
27
const { CLIENT_SETTINGS , ERRORS } = CONFIG ;
28
28
const {
29
29
SENDING_ENDPOINT ,
30
30
MAX_REDIRECTS ,
31
- USER_AGENT ,
32
31
TIMEOUT ,
33
32
TESTING_ENDPOINT ,
34
33
BULK_ENDPOINT ,
34
+ USER_AGENT ,
35
35
} = CLIENT_SETTINGS ;
36
36
const { ACCOUNT_ID_MISSING , BULK_SANDBOX_INCOMPATIBLE , TEST_INBOX_ID_MISSING } =
37
37
ERRORS ;
@@ -59,14 +59,15 @@ export default class MailtrapClient {
59
59
accountId,
60
60
bulk = false ,
61
61
sandbox = false ,
62
+ userAgent,
62
63
} : MailtrapClientConfig ) {
63
64
this . axios = axios . create ( {
64
65
httpAgent : new http . Agent ( { keepAlive : true } ) ,
65
66
httpsAgent : new https . Agent ( { keepAlive : true } ) ,
66
67
headers : {
67
68
Authorization : `Bearer ${ token } ` ,
68
69
Connection : "keep-alive" ,
69
- "User-Agent" : USER_AGENT ,
70
+ "User-Agent" : userAgent || USER_AGENT ,
70
71
} ,
71
72
maxRedirects : MAX_REDIRECTS ,
72
73
timeout : TIMEOUT ,
@@ -182,12 +183,12 @@ export default class MailtrapClient {
182
183
*/
183
184
public async send ( mail : Mail ) : Promise < SendResponse > {
184
185
const host = this . determineHost ( ) ;
185
-
186
186
this . validateTestInboxIdPresence ( ) ;
187
187
188
188
const url = `${ host } /api/send${
189
189
this . sandbox && this . testInboxId ? `/${ this . testInboxId } ` : ""
190
190
} `;
191
+
191
192
const preparedMail = encodeMailBuffers ( mail ) ;
192
193
193
194
return this . axios . post < SendResponse , SendResponse > ( url , preparedMail ) ;
0 commit comments