简体   繁体   English

Commons email错误的附件名称

[英]Commons email wrong attachment name

I'm using commons-email-1.2.jar and I have the issue with the attachment name. 我正在使用commons-email-1.2.jar ,我有附件名称的问题。

private static final String XML_ATTACHMENT_FILE_NAME = "Data.xml";
...
email.attach(ds, XML_ATTACHMENT_FILE_NAME, description, EmailAttachment.ATTACHMENT);

The problem is that the attachment name is not "Data.xml" but something else related to the media name stored on the database, somehow related to the description + file extension. 问题是附件名称不是"Data.xml"而是与存储在数据库中的媒体名称相关的其他内容,以某种方式与描述+文件扩展名相关。

Did somebody else face this issue? 别人是否面对这个问题?

UPDATE: On Windows (Outlook) it's working properly but the problem is on Mac. 更新:在Windows(Outlook)上它正常工作,但问题出在Mac上。

I'm not sure about the problem here without having logs in place, but you could try the verbose approach: 如果没有日志,我不确定这里的问题,但你可以尝试冗长的方法:

// Create the attachment
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("foo/foo.jpg");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Picture");
attachment.setName("Foo");

// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("foo.myserver.com");
email.addTo("foo@bar.com", "Foo Bar");
email.setFrom("example@example.com", "Example");
email.setSubject("Picture");
email.setMsg("Message body example");

// add the attachment
email.attach(attachment);

// send the email
email.send();

问题是在Mac和其他系统上,使用描述而不是附件名称,因此解决方案是将名称放在两个字段中:

email.attach(ds, XML_ATTACHMENT_FILE_NAME, XML_ATTACHMENT_FILE_NAME, EmailAttachment.ATTACHMENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM