使用 office365 发送电子邮件时,添加以下代码以获取 searchkey 以获取将来使用的线程 id(如果未生成线程 id),此代码给出错误 - “发送或更新操作无法执行,因为传入的更改密钥请求与项目的当前更改键不匹配”,如果我附加大小超过 3 MB 的更大文件。
FileAttachment fileAttachment = new FileAttachment( "C:\\send_files\\100 Percent
Automated Support - NCUCCC.pdf" );// 4.6MB file attached
AttachmentId attachmentId = service.createAttachment( fileAttachment, messageId );
messageId.setChangeKey( attachmentId.getRootItemChangeKey() );
FileAttachment fileAttachment1 = new FileAttachment( "C:\\send_files\\getting-started-with-hadoop-planning-guide.pdf" );// 3.1MB file attached
AttachmentId attachmentId1 = service.createAttachment( fileAttachment1, messageId );
messageId.setChangeKey( attachmentId1.getRootItemChangeKey() );
messageFromDrafts = service.getMessage( messageId );
searchKey = messageFromDrafts.getSearchKey();
service.send( messageId );
下面的代码可以很好地发送带有较大文件附件的电子邮件。所以最好使用此代码发送带有更大文件附件的电子邮件。
ItemInfoResponse response = service.send( messageId );
低于 3 MB 的文件大小作为附件没有任何问题