@@ -43,6 +43,8 @@ public class SendGrid {
43
43
private static final String PARAM_CONTENTS = "content[%s]" ;
44
44
private static final String PARAM_XSMTPAPI = "x-smtpapi" ;
45
45
private static final String PARAM_HEADERS = "headers" ;
46
+ private static final String TEXT_PLAIN = "text/plain" ;
47
+ private static final String UTF_8 = "UTF-8" ;
46
48
47
49
private String username ;
48
50
private String password ;
@@ -91,16 +93,16 @@ public HttpEntity buildBody(Email email) {
91
93
92
94
// If SMTPAPI Header is used, To is still required. #workaround.
93
95
if (tos .length == 0 ) {
94
- builder .addTextBody (String .format (PARAM_TO , 0 ), email .getFrom (), ContentType .create ("text/plain" , "UTF-8" ));
96
+ builder .addTextBody (String .format (PARAM_TO , 0 ), email .getFrom (), ContentType .create (TEXT_PLAIN , UTF_8 ));
95
97
}
96
98
for (int i = 0 , len = tos .length ; i < len ; i ++)
97
- builder .addTextBody (String .format (PARAM_TO , i ), tos [i ], ContentType .create ("text/plain" , "UTF-8" ));
99
+ builder .addTextBody (String .format (PARAM_TO , i ), tos [i ], ContentType .create (TEXT_PLAIN , UTF_8 ));
98
100
for (int i = 0 , len = tonames .length ; i < len ; i ++)
99
- builder .addTextBody (String .format (PARAM_TONAME , i ), tonames [i ], ContentType .create ("text/plain" , "UTF-8" ));
101
+ builder .addTextBody (String .format (PARAM_TONAME , i ), tonames [i ], ContentType .create (TEXT_PLAIN , UTF_8 ));
100
102
for (int i = 0 , len = ccs .length ; i < len ; i ++)
101
- builder .addTextBody (String .format (PARAM_CC , i ), ccs [i ], ContentType .create ("text/plain" , "UTF-8" ));
103
+ builder .addTextBody (String .format (PARAM_CC , i ), ccs [i ], ContentType .create (TEXT_PLAIN , UTF_8 ));
102
104
for (int i = 0 , len = bccs .length ; i < len ; i ++)
103
- builder .addTextBody (String .format (PARAM_BCC , i ), bccs [i ], ContentType .create ("text/plain" , "UTF-8" ));
105
+ builder .addTextBody (String .format (PARAM_BCC , i ), bccs [i ], ContentType .create (TEXT_PLAIN , UTF_8 ));
104
106
// Files
105
107
if (email .getAttachments ().size () > 0 ) {
106
108
Iterator it = email .getAttachments ().entrySet ().iterator ();
@@ -119,29 +121,29 @@ public HttpEntity buildBody(Email email) {
119
121
}
120
122
121
123
if (email .getHeaders ().size () > 0 )
122
- builder .addTextBody (PARAM_HEADERS , new JSONObject (email .getHeaders ()).toString (), ContentType .create ("text/plain" , "UTF-8" ));
124
+ builder .addTextBody (PARAM_HEADERS , new JSONObject (email .getHeaders ()).toString (), ContentType .create (TEXT_PLAIN , UTF_8 ));
123
125
124
126
if (email .getFrom () != null && !email .getFrom ().isEmpty ())
125
- builder .addTextBody (PARAM_FROM , email .getFrom (), ContentType .create ("text/plain" , "UTF-8" ));
127
+ builder .addTextBody (PARAM_FROM , email .getFrom (), ContentType .create (TEXT_PLAIN , UTF_8 ));
126
128
127
129
if (email .getFromName () != null && !email .getFromName ().isEmpty ())
128
- builder .addTextBody (PARAM_FROMNAME , email .getFromName (), ContentType .create ("text/plain" , "UTF-8" ));
130
+ builder .addTextBody (PARAM_FROMNAME , email .getFromName (), ContentType .create (TEXT_PLAIN , UTF_8 ));
129
131
130
132
if (email .getReplyTo () != null && !email .getReplyTo ().isEmpty ())
131
- builder .addTextBody (PARAM_REPLYTO , email .getReplyTo (), ContentType .create ("text/plain" , "UTF-8" ));
133
+ builder .addTextBody (PARAM_REPLYTO , email .getReplyTo (), ContentType .create (TEXT_PLAIN , UTF_8 ));
132
134
133
135
if (email .getSubject () != null && !email .getSubject ().isEmpty ())
134
- builder .addTextBody (PARAM_SUBJECT , email .getSubject (), ContentType .create ("text/plain" , "UTF-8" ));
136
+ builder .addTextBody (PARAM_SUBJECT , email .getSubject (), ContentType .create (TEXT_PLAIN , UTF_8 ));
135
137
136
138
if (email .getHtml () != null && !email .getHtml ().isEmpty ())
137
- builder .addTextBody (PARAM_HTML , email .getHtml (), ContentType .create ("text/plain" , "UTF-8" ));
139
+ builder .addTextBody (PARAM_HTML , email .getHtml (), ContentType .create (TEXT_PLAIN , UTF_8 ));
138
140
139
141
if (email .getText () != null && !email .getText ().isEmpty ())
140
- builder .addTextBody (PARAM_TEXT , email .getText (), ContentType .create ("text/plain" , "UTF-8" ));
142
+ builder .addTextBody (PARAM_TEXT , email .getText (), ContentType .create (TEXT_PLAIN , UTF_8 ));
141
143
142
144
String tmpString = email .smtpapi .jsonString ();
143
145
if (!tmpString .equals ("{}" ))
144
- builder .addTextBody (PARAM_XSMTPAPI , tmpString , ContentType .create ("text/plain" , "UTF-8" ));
146
+ builder .addTextBody (PARAM_XSMTPAPI , tmpString , ContentType .create (TEXT_PLAIN , UTF_8 ));
145
147
146
148
return builder .build ();
147
149
}
0 commit comments