@@ -79,7 +79,7 @@ public static class Email {
7979 public Map headers = new HashMap ();
8080
8181 public Email () {
82- this .smtpapi = new SMTPAPI ();
82+ this .smtpapi = new SMTPAPI ();
8383 }
8484
8585 public Email addTo (String to ) {
@@ -122,52 +122,53 @@ public Email setHtml(String html) {
122122 return this ;
123123 }
124124
125- public Email addSubstitution (String key , String [] val ) {
126- this .smtpapi .addSubstitutions (key , val );
127- return this ;
125+ public Email addSubstitution (String key , String [] val ) {
126+ this .smtpapi .addSubstitutions (key , val );
127+ return this ;
128128 }
129-
130- public Email addUniqueArg (String key , String val ) {
129+
130+ public Email addUniqueArg (String key , String val ) {
131131 this .smtpapi .addUniqueArg (key , val );
132132 return this ;
133133 }
134-
135- public Email addCategory (String category ) {
134+
135+ public Email addCategory (String category ) {
136136 this .smtpapi .addCategory (category );
137137 return this ;
138138 }
139-
140- public Email addSection (String key , String val ) {
141- this .smtpapi .addSection (key , val );
139+
140+ public Email addSection (String key , String val ) {
141+ this .smtpapi .addSection (key , val );
142142 return this ;
143143 }
144-
144+
145145 public Email addFilter (String filter_name , String parameter_name , String parameter_value ) {
146- this .smtpapi .addFilter (filter_name , parameter_name , parameter_value );
147- return this ;
146+ this .smtpapi .addFilter (filter_name , parameter_name , parameter_value );
147+ return this ;
148148 }
149149
150- public Email addAttachment (File file , String name ) throws FileNotFoundException {
151- return this .addAttachment (new FileInputStream (file ), name );
150+ public Email addAttachment (String name , File file ) {
151+ this .attachments .put (name , file );
152+ return this ;
152153 }
153154
154- public Email addAttachment (String file , String name ) {
155+ public Email addAttachment (String name , String file ) {
155156 this .attachments .put (name , file );
156157 return this ;
157158 }
158159
159- public Email addAttachment (InputStream file , String name ) {
160+ public Email addAttachment (String name , InputStream file ) {
160161 Scanner scanner = new Scanner (file , "UTF-8" );
161162 String buffer = new String ();
162163 while (scanner .hasNextLine ()) {
163164 buffer += scanner .nextLine ();
164165 }
165166 scanner .close ();
166- return this .addAttachment (buffer , name );
167+ return this .addAttachment (name , buffer );
167168 }
168-
169- public Email addHeader (String key , String val ) {
170- this .headers .put (key , val );
169+
170+ public Email addHeader (String key , String val ) {
171+ this .headers .put (key , val );
171172 return this ;
172173 }
173174
@@ -177,17 +178,17 @@ public Map toWebFormat() {
177178 // updateMissingTo - There needs to be at least 1 to address,
178179 // or else the mail won't send.
179180 if ((this .to == null || this .to .isEmpty ()) && this .from != null && !this .from .isEmpty ()) {
180- String value = this .from ;
181+ String value = this .from ;
181182 body .put (PARAM_TO , value );
182183 }
183184
184185 if (this .from != null && !this .from .isEmpty ()) {
185- String value = this .from ;
186+ String value = this .from ;
186187 body .put (PARAM_FROM , value );
187188 }
188189
189190 if (this .fromname != null && !this .fromname .isEmpty ()) {
190- String value = this .fromname ;
191+ String value = this .fromname ;
191192 body .put (PARAM_FROMNAME , value );
192193 }
193194
@@ -217,14 +218,14 @@ public Map toWebFormat() {
217218 body .put (PARAM_HTML , value );
218219 }
219220
220- if (!this .headers .isEmpty ()) {
221+ if (!this .headers .isEmpty ()) {
221222 JSONObject json_headers = new JSONObject (this .headers );
222223 String serialized_headers = json_headers .toString ();
223224 body .put (PARAM_HEADERS , serialized_headers );
224- }
225+ }
225226
226227 if (!this .smtpapi .jsonString ().equals ("{}" )) {
227- String value = this .smtpapi .jsonString ();
228+ String value = this .smtpapi .jsonString ();
228229 body .put (PARAM_XSMTPAPI , value );
229230 }
230231
0 commit comments