附件文件名在电子邮件中显示为 "mime"

Attachment file name appears as "mime" in email

当我的附件文件名很长时,电子邮件中的文件名显示为 "mime" 而不是实际文件名。附件文件名的长度是否有限制?或者这个问题是由其他原因引起的?

代码如下:

java.util.Properties properties=System.getProperties();
properties.put("mail.smtp.host",smtpHost);
Session session=Session.getDefaultInstance(properties, null);

MimeMessage message = new MimeMessage(session);
Address fromAddress=new InternetAddress(from);
message.setFrom(fromAddress);
Address[] toAddresses=InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.TO, toAddresses);
Address[] ccAddresses=InternetAddress.parse(cc);
message.setRecipients(Message.RecipientType.CC, ccAddresses);
Address[] bccAddresses=InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.BCC, bccAddresses);
message.setSubject(subject);                       

//Start - Send HTML Message                    
MimeBodyPart mbpa2 = new MimeBodyPart();
mbpa2.setText(body);
mbpa2.addHeaderLine("Content-Type: text/html; charset=\"iso-8859-1\"");
mbpa2.addHeaderLine("Content-Transfer-Encoding: quoted-printable");                                                             
Multipart mp2 = new MimeMultipart("alternative");                    
mp2.addBodyPart(mbpa2);                    


// attach the files to the message
if ( attachments != null && attachments.length > 0 ) 
{
    for (String filename:attachments) 
    { 
        FileDataSource fds = new FileDataSource(filename);
        MimeBodyPart mbp3 = new MimeBodyPart();
        mbp3.setDataHandler(new DataHandler(fds));
        mbp3.setFileName(fds.getName());                            
        // attach the file to the message
        mp2.addBodyPart(mbp3);                                                        
    }
} 
// End of file attachment

message.setContent(mp2);                       
//End - Send HTML Message

Transport transport=session.getTransport("smtp");   
transport.connect(smtpHost, "", "");
transport.sendMessage(message, message.getAllRecipients());
transport.close();

没有限制,但长文件名的编码方式会有所不同,如果您使用的是旧邮件程序,它可能无法理解该编码,而是用一些通用名称代替。您可以将系统 属性 mail.mime.encodeparameters 设置为 false 以禁用此编码。