我在写一个发送邮件程序,提交的中文怎么会是乱码呢?从服务器返回的中文都能正确显示:
public String testSendMail(){
StringBuffer retJsonStr=new StringBuffer();
if("".equals(mailTo)||mailTo==null){
retJsonStr.append("{errors:[{id:'to', msg:'请输入收件人地址!'}]}");
ByteArrayInputStream bais=new ByteArrayInputStream(retJsonStr.toString().getBytes());
this.inputStream=bais;
return SUCCESS;
}
if("".equals(mailSubject)||mailSubject==null){
retJsonStr.append("{errors:[{id:'subject', msg:'请输入邮件主题!'}]}");
ByteArrayInputStream bais=new ByteArrayInputStream(retJsonStr.toString().getBytes());
this.inputStream=bais;
return SUCCESS;
}
if("".equals(mailBody)||mailBody==null){
retJsonStr.append("{errors:[{id:'body', msg:'请输入邮件内容!'}]}");
ByteArrayInputStream bais=new ByteArrayInputStream(retJsonStr.toString().getBytes());
this.inputStream=bais;
return SUCCESS;
}
SendMail mailBean=new SendMail();
mailBean.setMailFrom("misswolf@sdaf.com");
mailBean.setMailTo(mailTo);
mailBean.setMailSubject(mailSubject);
mailBean.setMailBody(mailBody);
mailBean.setMailHost("smtp.gmail.com");
retJsonStr.append("{success:true, key:'success',msg:'"+mailBean.sendMail()+"', type:'type'}\n");
ByteArrayInputStream bais=new ByteArrayInputStream(retJsonStr.toString().getBytes());
this.inputStream=bais;
return SUCCESS;
}