@@ -43,6 +43,8 @@ public class SendGrid {
4343 private static final String PARAM_CONTENTS = "content[%s]" ;
4444 private static final String PARAM_XSMTPAPI = "x-smtpapi" ;
4545 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" ;
4648
4749 private String username ;
4850 private String password ;
@@ -91,16 +93,16 @@ public HttpEntity buildBody(Email email) {
9193
9294 // If SMTPAPI Header is used, To is still required. #workaround.
9395 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 ));
9597 }
9698 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 ));
98100 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 ));
100102 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 ));
102104 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 ));
104106 // Files
105107 if (email .getAttachments ().size () > 0 ) {
106108 Iterator it = email .getAttachments ().entrySet ().iterator ();
@@ -119,29 +121,29 @@ public HttpEntity buildBody(Email email) {
119121 }
120122
121123 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 ));
123125
124126 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 ));
126128
127129 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 ));
129131
130132 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 ));
132134
133135 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 ));
135137
136138 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 ));
138140
139141 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 ));
141143
142144 String tmpString = email .smtpapi .jsonString ();
143145 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 ));
145147
146148 return builder .build ();
147149 }
0 commit comments