这是获取电子邮件的sender
代码subject
。通过此代码,我看到显示了正确的主题,但我看到了不同格式的发件人地址。
Properties props = new Properties();
props.put("mail.imap.host" , "imap.gmail.com" );
props.put("mail.imap.user" , "username");
// User SSL
props.put("mail.imap.socketFactory" , 993);
props.put("mail.imap.socketFactory.class" , "javax.net.ssl.SSLSocketFactory" );
props.put("mail.imap.port" , 993 );
Session session = Session.getDefaultInstance(props , new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username" , "password");
}
});
try {
Store store = session.getStore("imap");
store.connect("imap.gmail.com" , "username" , "password");
Folder fldr = store.getFolder("Inbox");
fldr.open(Folder.READ_ONLY);
Message msgs[] = fldr.getMessages();
for(int i = 0 ; i < msgs.length ; i++) {
System.out.println(msgs[i].getFrom() + "<-- FROM" + " " + msgs[i].getSubject() + "<---Subject");
}
} catch(Exception exc) {
}
}
输出是:
[Ljavax.mail.internet.InternetAddress;@1462851<-- FROMGet Gmail on your mobile phone<---Subject
[Ljavax.mail.internet.InternetAddress;@bdab91<-- FROMImport your contacts and old email<---Subject
[Ljavax.mail.internet.InternetAddress;@4ac00c<-- FROMCustomize Gmail with colors and themes<---Subject
[Ljavax.mail.internet.InternetAddress;@1865b28<-- FROMtester<---Subject
它是什么形式?(@1462851)
我希望显示发件人的电子邮件地址而不是。@1462851
我该怎么做?