Java 프로그램을 사용하여 Gmail 계정에서 첨부 파일을 다운로드해야합니다. Apache Camel을 사용하십시오.Gmail에서 메일 첨부 파일 다운로드, Exchange 가져 오기 [MailMessage : null]
내가 무엇입니까 실행하는 동안,
교환 [은 MailMessage : 널 (null)], 따라서 attachments.size는()
0도
@Test
public void configureExcange() throws Exception {
try {
CamelContext context = new DefaultCamelContext();
Endpoint endpoint =
context.getEndpoint("imaps://imap.gmail.com?username=" + mailId + "&password=" + password
+ "&delete=false&unseen=true&consumer.delay=60000");
// PollingConsumer consumer = endpoint.createPollingConsumer();
Exchange exchange = endpoint.createExchange();
process(exchange);
} catch (Exception e) {
e.printStackTrace();
}
}
public void process(Exchange exchange) throws Exception {
// the API is a bit clunky so we need to loop
Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
if (attachments.size() > 0) {
for (String name : attachments.keySet()) {
DataHandler dh = attachments.get(name);
// get the file name
String filename = dh.getName();
// get the content and convert it to byte[]
byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, dh.getInputStream());
// write the data to a file
FileOutputStream out = new FileOutputStream(filename);
out.write(data);
out.flush();
out.close();
}
}
}
을 내 테스트 코드를 게시 오전
첨부 파일을 어떻게받을 수 있습니까?