msg.setSubject(MimeUtility.encodeText("测试", "GBK", "B"));

解决方案 »

  1.   

    //正文
    MimeBodyPart bodyPart = new MimeBodyPart() ;
    bodyPart.setContent( MimeUtility.encodeText(mailBody,"GBK","B"),"text/html;charset=gb2312" ) ;
    正文部分该怎么写,按照上面的写法会出现乱码
      

  2.   

    1.在JavaMail的api中有这些方法的说明
    2.试试bodyPart.setContent(mailBody, "text/html;charset=gb2312");
      

  3.   

    我开始用的这个bodyPart.setContent(mailBody, "text/html;charset=gb2312");
    不过发到etang 邮箱的内容为???????
    如果用bodyPart.setContent( MimeUtility.encodeText(mailBody,"GBK","B"),"text/html;charset=gb2312" ) ;内容是一些大写字母
    怎么解决啊?谢谢,
      

  4.   

    cbhyk:能不能留下你的联系方式?
      

  5.   

    试一下在接收的时候调用MimeUtility.decodeText方法解码邮件内容.
    看一下JavaMail的api,应该能解决的。
    我上不了QQ,MSN,很少收邮件([email protected]),一般都挂在MSDN上。
      

  6.   

    接收邮件的是 etang的邮件服务器啊,我没发转换啊
      

  7.   

    我用以下代码发邮件,用FoxMail收下来中文正常:
    String host = ...;
    int port = 25;
    String from = ...;
    String to = ...;Properties props = new Properties();
    props.put("mail.smtp.host", host);
    if (port != -1)
    props.put("mail.smtp.port", String.valueOf(port));
    Session session = Session.getInstance(props, null);
    MimeMessage msg = new MimeMessage(session);
    try
    {
    msg.setFrom(new InternetAddress(from));
    msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
    msg.setSubject("中文标题", "GB2312");
    msg.setContent("中文内容", "text/html;charset=GB2312");
    Transport.send(msg);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }