Ok so i have been searching google and other threads for hours trying to get this issue figured out.
Basically i have been making a program that send emails and text messages and also lets you check your inbox for unread messages you may have. I cant seem to get the content of an unread message to print out if it was sent by someone not sending it with my program.
This is the message i get printed out instead of the message body (“javax.mail.internet.MimeMultipart@176e552”)
I do not get any errors, it just prints out that message as if it was the body of the email.
What i dont understand is that im not sending an attachment with the email so why is it doing this?, The only think i can think of is that some emails have links in them and it thinks the links are attachments?
Again it only does this when it reading from an email that was sent from the email providers website itself, not my program.
Here is the code i have for when it reads the message.
try
{
Properties prop = new Properties();
prop.setProperty("mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.pop3.socketFactory.fallback", "false");
prop.setProperty("mail.pop3.port", s.popPort);
prop.setProperty("mail.pop3.socketFactory.port", s.popPort);
prop.put("mail.pop3.host", host);
prop.put("mail.store.protocol", "pop3s");
Session session = Session.getDefaultInstance(prop);
store = session.getStore();
System.out.println("your ID is : " + username);
SimpleTextSender.textArea.setText("Connecting...");
try
{
store.connect(host, username, password);
} catch (AuthenticationFailedException e)
{
JOptionPane.showMessageDialog(null, "" + e.getMessage());
}
SimpleTextSender.textArea.setText("Connected...");
Folder inbox = store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] msg = inbox.getMessages();
for (int i = 0; i < msg.length; i++)
{
int answer = JOptionPane
.showConfirmDialog(null, "Open message titled '"
+ msg[i].getSubject() + "'?");
if (answer == 0)
{
handleText(msg[i]);
}
else if (answer == 1)
{
break;
}
else
{
// i = msg.length+1;
break;
}
}
if (inbox != null)
{
inbox.close(true);
}
if (store != null)
{
store.close();
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
private void handle(Message msg) throws Exception
{
JOptionPane.showMessageDialog(null, "From: "
+ msg.getFrom()[0].toString() + "\n" + "Sent: "
+ msg.getSentDate() + "\n");
}
private void handleText(Message msg) throws Exception
{
//handle(msg);
//String messageText = msg.getContent().toString();
SimpleTextSender.textArea.setText(msg.getContent().toString());
}
