Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Javax mail not working when exported(javax Folder.getMessages works in IDE but not when I export it)
Javax mail not working when exported [message #1829460] Sat, 04 July 2020 04:06
Joseph Gewelber-Williams is currently offline Joseph Gewelber-WilliamsFriend
Messages: 1
Registered: July 2020
Junior Member
I'm fairly new to eclipse and new to working with e-mails in java. My code works perfectly when ran out of eclipse but as an executable JAR it won't work. It all boils down to the Folder.getMessages function. My program logs into the gmail account just fine and even finds the mail folder, but once it tries to get the messages it just crashes. I can't figure out why it would only work in IDE but it's very frustrating.

Here is the function:
public static String[] checkMail(String host, String storeType, String user, String pass, String headerReq) throws IOException
			Properties properties = new Properties();
			properties.put("", host);
			properties.put("mail.pop3.port", "995");
			properties.put("mail.pop3.starttls.enable", "true");
			Session emailSession = Session.getDefaultInstance(properties);
			Store store = emailSession.getStore("pop3s");
			store.connect(host, user, pass);
			Folder emailFolder = store.getFolder("INBOX");;
			Message[] messages = emailFolder.getMessages();
			ArrayList<String> messageContent = new ArrayList<String>();
			for (int i = 0; i < messages.length; i++)
				if (messages[i].getSubject() != null)
					if (messages[i].getSubject().toLowerCase().contains(headerReq.toLowerCase()))
						writeToFile(messages[i].getSubject().substring(7) + "\n","senders", true);
			String[] contentArray = new String[messageContent.size()];
			for (int i = 0; i < contentArray.length; i++)
				contentArray[i] = messageContent.get(i);
			return contentArray;
		catch (NoSuchProviderException e)
			writeToFile("No Provider", "MailErrorLog", true);
		catch (MessagingException e)
			writeToFile("MessagingException", "MailErrorLog", true);
		catch (Exception e)
			writeToFile("Exception?", "MailErrorLog", true);
		return null;

I really appreaciate your time!
Previous Topic:JavaFX Sanity Check
Next Topic:Moving Workspace
Goto Forum:

Current Time: Sat Jan 16 00:06:23 GMT 2021

Powered by FUDForum. Page generated in 0.03082 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top