8
8
* - apikey : The mailgun secret api key
9
9
* - domain : The mailgun domain to send the email through
10
10
*
11
+ * An optional property, "baseURL" is required when using an EU region
12
+ * - baseURL : The mailgun region where the Mailgun domain was created
13
+ *
11
14
* @author Scott Steinbeck <[email protected] >
12
15
*/
13
16
component
@@ -24,7 +27,6 @@ component
24
27
MailgunProtocol function init ( struct properties = {} ){
25
28
variables .name = " Mailgun" ;
26
29
variables .DEFAULT_TIMEOUT = 30 ; // in seconds
27
- variables .MAILGUN_APIURL = " https://api.mailgun.net/v3/" ;
28
30
// super size it
29
31
super .init ( argumentCollection = arguments );
30
32
@@ -40,6 +42,14 @@ component
40
42
throw ( message = " ApiKey is Required" , type = " MailgunProtocol.PropertyNotFound" );
41
43
}
42
44
45
+ // Check for Base URL property
46
+ if ( ! propertyExists ( " baseURL" ) ) {
47
+ // No baseURL key was found, so use the US default.
48
+ variables .MAILGUN_APIURL = " https://api.mailgun.net/v3/" ;
49
+ } else {
50
+ variables .MAILGUN_APIURL = getProperty ( " baseURL" );
51
+ }
52
+
43
53
return this ;
44
54
}
45
55
@@ -101,7 +111,7 @@ component
101
111
data .delete ( " bodyTokens" ); // cleanup payload
102
112
103
113
// Process the mail attachments and encode them how mailgun likes them
104
- attachments = arguments .payload
114
+ var attachments = arguments .payload
105
115
.getMailParams ()
106
116
.filter ( function ( thisParam ){
107
117
return structKeyExists ( arguments .this Param , " file" );
@@ -185,7 +195,14 @@ component
185
195
}
186
196
187
197
// Inflate HTTP Results
188
- var mailgunResults = deserializeJSON ( httpResults .fileContent .toString () );
198
+ if ( isJSON ( httpResults .fileContent .toString () ) ) {
199
+ var mailgunResults = deserializeJSON ( httpResults .fileContent .toString () );
200
+ } else {
201
+ results .messages = [ ' Error sending mail. Mailgun returned "#httpResults .fileContent .toString () #".' ];
202
+
203
+ return results ;
204
+ }
205
+
189
206
// Process Mailgun Results
190
207
if ( mailgunResults .message eq " Queued. Thank you." ) {
191
208
results .error = false ;
0 commit comments