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
	{
		try
		{	
			Properties properties = new Properties();
			
			properties.put("mail.pop3.host", 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");
			emailFolder.open(Folder.READ_ONLY);
			
			Message[] messages = emailFolder.getMessages();
			
			ArrayList<String> messageContent = new ArrayList<String>();
			
			for (int i = 0; i < messages.length; i++)
			{
				if (messages[i].getSubject() != null)
				{
					System.out.println(messages[i].getSubject());
					if (messages[i].getSubject().toLowerCase().contains(headerReq.toLowerCase()))
					{
						messageContent.add(getEmailText(messages[i]));
						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);
			}
			
			emailFolder.close(false);
			store.close();
			
			return contentArray;
		}
		catch (NoSuchProviderException e)
		{
			writeToFile("No Provider", "MailErrorLog", true);
			e.printStackTrace();
		}
		catch (MessagingException e)
		{
			writeToFile("MessagingException", "MailErrorLog", true);
			e.printStackTrace();
		}
		catch (Exception e)
		{
			writeToFile("Exception?", "MailErrorLog", true);
			e.printStackTrace();
		}
		
		return null;
	}


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


Current Time: Thu Apr 25 17:32:31 GMT 2024

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

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

Back to the top