Results 1 to 6 of 6
Thread: javamail, getSubject, and if()
- 01-10-2011, 08:50 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
javamail, getSubject, and if()
Hey, im new to java but have coded in multiple other languages including objective-c. I'm currently working on a program that gets mail from an smpt server and scans the messages for ones with a certain subject:"Tester" So far, I have the program retrieving the messages and I have a message with the Subject:"Tester", but when I use an if statement to check if the subject is "Tester" it returns false. My code is below. I am wondering if there is any special format for subjects or something?
I have other voids to retrieve certain information ie:getMessageCount()Java Code:public void getRecieptMessage() throws Exception { Message m = null; try { for (int i = 1; i <= getMessageCount(); i++) { m = folder.getMessage(i); System.out.println(m.getSubject()); if (m.getSubject() == "Tester"){ System.out.println("found"); printMessage(i); } } } catch (IndexOutOfBoundsException iex) { System.out.println("Message number out of range"); } }
but the focus is on the if statement, it just won't return true.
- 01-10-2011, 11:22 AM #2
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
write your if statement like.
if(message.getSubject().equals("Tester"))
{
System.out.println("found");
printMessage(i);
}
good luck!!!
- 01-10-2011, 04:11 PM #3
Senior Member
- Join Date
- Dec 2010
- Posts
- 100
- Rep Power
- 0
When checking for equality of String objects, always use the .equals methods.
Best,--user0--
- 01-10-2011, 04:50 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Thanks guys so much! Iv'e seen then before in a few hey0 plugins for minecraft and totally forgot about it.
- 01-10-2011, 04:55 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Adress[]
One other thing. Say next I want to test the from address. I want to see if its from "usr@email.com" how would i go about doing this? I know there is a class:"Address[]" but im not sure how to set it to a certain email adress. I'm hoping the code will look something like this:
Java Code:Address[] address = "usr@email.com"; //thats the part i need help with if(m.getAddress().equals(address)){ System.out.println("found"); printMessage(i); }
- 01-11-2011, 07:09 AM #6
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
Similar Threads
-
Help with javamail ??
By nikunj in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-02-2011, 12:12 PM -
Javamail
By johniem in forum New To JavaReplies: 0Last Post: 07-14-2010, 03:00 PM -
JavaMail API
By eponcedeleon in forum Advanced JavaReplies: 1Last Post: 02-28-2010, 12:39 AM -
Javamail
By johniem in forum New To JavaReplies: 1Last Post: 01-29-2010, 03:24 PM -
JavaMail Jar
By rummy in forum Advanced JavaReplies: 1Last Post: 01-21-2010, 03:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks