Search The ForumSearch   RegisterRegister  LoginLogin

MailBee IMAP4

 AfterLogic Forum : MailBee IMAP4
Subject Topic: IMAP4 Search for messages Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 13 May 2009 at 8:25am | IP Logged Quote niklas

Hi,

Im from Sweden and im not that good in english but I will do my best ;)

I want to check for new emails and upload the attached file to my web server from a specific sender.

First of all I need to check for new e-mails from this specific sender and then check if a file is attached. If the file is attached I want to get access to the file and then upload it to my web server - automaticly.

Can you help me?

Back to Top View niklas's Profile Search for other posts by niklas
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 14 May 2009 at 6:24am | IP Logged Quote Igor

This can be achieved in multiple ways. We suggest to perform the task in 4 steps:

1. Logging on IMAP account.
2. Checking for new mails from specified sender.
3. Analyzing attachments.
4. Logging off.

Let's take a closer look at this step-by-step from MailBee Objects perspective.

1. Logging on IMAP account

Detailed information and example on this is available here. For now, let's assume we need to access IMAP account using regular port 143 and supply account credentials:
Code:
Set Mailer = CreateObject("MailBee.IMAP4")
Mailer.LicenseKey = "put your license key here"
Mailer.Connect("mailserver.com", 143, "MyName", "MyPassword")


2. Checking for new mails from specified sender

This is done using Search method with UNSEEN and FROM <string> keys combined, e.g.:
Code:
SearchResults = Mailer.Search(True, "UNSEEN FROM johndoe@mailserver.com")


3. Analyzing attachments

Once you have message UIDs, you can download those messages:
Code:
    If Not IsEmpty(SearchResults) Then
      For I = LBound(SearchResults) To UBound(SearchResults)
        Set Message = Mailer.RetrieveSingleMessage(SearchResults(I), True)
        If Not Message Is Nothing Then

           ...

        End If
      Next
    End If


You can save message attachments to disk using the example on this documentation page.

4. Logging off

The simplest part:
Code:
Mailer.Disconnect


--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 15 May 2009 at 10:49am | IP Logged Quote niklas

Hi Igor,

thanks for your help.

I manage to do exactly the same as you but I dont have the licence for POP3, only IMAP4. Look at the title of my post. So I cant save and download attachments the way you prefer.

"Object required..."

How can we go on from now?
Back to Top View niklas's Profile Search for other posts by niklas
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 16 May 2009 at 3:23am | IP Logged Quote Igor

Quote:
but I dont have the licence for POP3


You don't need one. I assume you're referring to SaveFile example, but in our case messages are downloaded from IMAP server using RetrieveSingleMessage, then they should be saved using SaveFile method. This method works with Message object, and it doesn't matter if the message was downloaded via IMAP or POP3.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 18 May 2009 at 5:19am | IP Logged Quote niklas

Igor,

Thanks for all help, it works fine now.

I have some other questions aswell.

How can I see mails from a specific sender and a specific subjecttitle? With your example we just see mail from a specific sender.
Back to Top View niklas's Profile Search for other posts by niklas
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 18 May 2009 at 5:24am | IP Logged Quote Andrew

Please refer to IMAP4.Search method description. You can find the following condition there:

SUBJECT <string> - messages that contain specified string in "Subject:"


Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 18 May 2009 at 5:50am | IP Logged Quote niklas

It worked! Thanks for your help!
Back to Top View niklas's Profile Search for other posts by niklas
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 25 May 2009 at 6:53am | IP Logged Quote niklas

I have two more questions.

If I have a subject like this:
Report View of 08. Group Sales Report - UK

How can I make it work with this? Just a single word was okej, but not this.

Second,

If I want to check for more unseen messages, from several other senders with diffrent subjects.

How do I do that?
Back to Top View niklas's Profile Search for other posts by niklas
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 25 May 2009 at 8:07am | IP Logged Quote Igor

Quote:
If I have a subject like this:
Report View of 08. Group Sales Report - UK

How can I make it work with this? Just a single word was okej, but not this.


Make sure you place the Subject text in "quotes".

Quote:
If I want to check for more unseen messages, from several other senders with diffrent subjects.


It is possible to combine multiple search patterns in one Search method call using OR key in form of OR Condition1 Condition2 ; you can also group patterns via "AND" condition by separating them with spaces. Brackets ( ) can be used as well. For details on Search syntax, check RFC3501, you can use any search technique available there.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 21 June 2009 at 11:50pm | IP Logged Quote niklas

Hi Igor,

I canīt get multiple search function to work.

This is the code I have and I have been trying with all kinds of code and nothing works.

SearchResults = Mailer.Search(True, "UNSEEN FROM niklas@somemail.com SUBJECT ""Testing with a subject"" OR UNSEEN FROM niklas@somemail.com SUBJECT ""Testing with another subject""")

What can I do to make this function to work?
Back to Top View niklas's Profile Search for other posts by niklas
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 22 June 2009 at 1:03am | IP Logged Quote Igor

According to IMAP Search documentation page, OR keyword should preceed the 1st search pattern, i.e. it's OR pattern1 pattern2, not pattern1 OR pattern2. Please note that you can use parentheses to group multiple search criteria.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 22 June 2009 at 1:06am | IP Logged Quote Igor

You can test your search patterns on IMAP server directly via telnet:
Code:
telnet yourserver 143

01 login YOUR_USERNAME YOUR_PASSWORD
01 select "Inbox"
01 uid search YOUR_SEARCH_CONDITION
01 logout


--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 22 June 2009 at 6:36am | IP Logged Quote niklas

Hi Igor,

It worked, but just with two patterns. How will I go on from now?
Back to Top View niklas's Profile Search for other posts by niklas
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 22 June 2009 at 6:47am | IP Logged Quote Igor

Like I said previously,
Quote:
Please note that you can use parentheses to group multiple search criteria.


Thus, if you need 4 search patterns to be used via OR construction, this would look like:
OR condition1 (OR condition2 (OR condition3 condition4))

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 22 June 2009 at 8:00am | IP Logged Quote niklas

Hi Igor,

thanks for all your help. You must be tired of me ;)

It still doesnt work. Please check my code:

SearchResults = Mailer.Search(True, "OR UNSEEN FROM niklas@somemail.com SUBJECT ""01. Report"" (OR UNSEEN FROM niklas@somemail.com SUBJECT ""02. Report"" (OR UNSEEN FROM niklas@somemail.com SUBJECT ""03. Report""))")


Back to Top View niklas's Profile Search for other posts by niklas
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 23 June 2009 at 3:07am | IP Logged Quote Andrew

If we understood you correctly, you need to find all new messages from niklas@somemail.com with subjects "01. Report", "02. Report", "03. Report".

In this case, the search condition should look like:

Code:
UNSEEN FROM "niklas@somemail.com" OR SUBJECT "01. Report" (OR SUBJECT "02. Report" SUBJECT "03. Report")


Does it work? If doesn't, please try each condition separately:
- UNSEEN
- FROM "niklas@somemail.com"
- SUBJECT "01. Report"
- SUBJECT "02. Report"
- SUBJECT "03. Report"

If each of all the conditions return at least one result, try their simple combinations, like:
- UNSEEN FROM "niklas@somemail.com"
- UNSEEN SUBJECT "01. Report"
- FROM "niklas@somemail.com" SUBJECT "01. Report"

Please let us know the outcome.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 23 June 2009 at 6:51am | IP Logged Quote niklas

Hi Andrew,

I have now test all your code but nothing works. I only get the first subject to work. I have tried all different ways with OR and parentheses to group but nothing works.

I need to have this fixed before the end of the week.

Please let me know if you got some other tips.
Back to Top View niklas's Profile Search for other posts by niklas
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 23 June 2009 at 6:58am | IP Logged Quote niklas

This code works, but nothing else.

SearchResults = Mailer.Search(True, "OR UNSEEN FROM ""niklas@somemail.com"" SUBJECT ""01. Test""")
Back to Top View niklas's Profile Search for other posts by niklas
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 23 June 2009 at 6:59am | IP Logged Quote niklas

Ooops, remove "OR" then it works, but just with one.
Back to Top View niklas's Profile Search for other posts by niklas
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 24 June 2009 at 12:41am | IP Logged Quote Andrew

Please provide us with a test account on your IMAP server with some test messages and specify exact search condition and point to messages which should be found.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 24 June 2009 at 1:59am | IP Logged Quote niklas

Hi Andrew,

I cant give you any access to our IMAP server due the high security. Sorry for that!

Havent you had these questions before? Dont you make any tests before sendning me the code? Im not the one who sould be testing how things works. Im the customer and I pay for your license and if I cant get things to work as you recommend in your support documentation, what shall I do?

I just want you to help me, but I cant give you any access to our IMAP server.
Back to Top View niklas's Profile Search for other posts by niklas
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 24 June 2009 at 2:59am | IP Logged Quote Andrew

Actually, I had tested what I suggested to you. I tried those search queries on our local IMAP server. However, some IMAP servers may have different behavior and what works on one IMAP server may not work on another one. Another reason is that IMAP servers don't parse MIME sources for search, they search in raw MIME sources and it's possible that you see a text, then try to search for it, but get no results because that text a bit differs from its MIME representation. So, if we get a test account, we'd be able to investigate what's wrong and find a workaround.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
niklas
Newbie
Newbie


Joined: 08 November 2008
Location: Sweden
Online Status: Offline
Posts: 15
Posted: 24 June 2009 at 3:51am | IP Logged Quote niklas

Ok,

but we cant get you any access to our IMAP server, thats one thing for sure. Im not the one whos in charge. What can we do instead?
Back to Top View niklas's Profile Search for other posts by niklas
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 24 June 2009 at 4:10am | IP Logged Quote Andrew

In that case, we recommend you the following.

Try the following 3 simple conditions:

- SUBJECT "01. Report"
- SUBJECT "02. Report"
- SUBJECT "03. Report"

It's important to check all three cases to make sure there's at least one result in each case.

If you have at least one result in each case, try the following condition:

- OR SUBJECT "01. Report" SUBJECT "02. Report"

You should get at least 2 results.

If you got 2 results, try the following:

OR SUBJECT "01. Report" (OR SUBJECT "02. Report" SUBJECT "03. Report")

If you got at least three results, just add all other necessary conditions. This condition doesn't give you at least three results, try it without brackets.

We'd recommend you to try that in telnet directly:

Code:
telnet yourserver 143

01 login YOUR_USERNAME YOUR_PASSWORD
01 select "Inbox"
01 uid search SUBJECT "01. Report"
01 uid search SUBJECT "02. Report"
01 uid search SUBJECT "03. Report"
01 uid search OR SUBJECT "01. Report" SUBJECT "02. Report"
01 uid search OR SUBJECT "01. Report" (OR SUBJECT "02. Report" SUBJECT "03. Report")
01 logout


If something is wrong, please provide us with entire log of your IMAP session. In my case, it looks as follows:

Code:
* OK CommuniGate Pro IMAP Server 4.0.5 at u-server.dom2.local ready
01 login test test
01 OK completed
01 select "Inbox"
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] limited
* 22 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 302733082] UIDs valid
01 OK [READ-WRITE] SELECT completed
01 uid search SUBJECT "field"
* SEARCH 101
01 OK completed
01 uid search SUBJECT "test"
* SEARCH 84 85 86 94 95 96
01 OK completed
01 uid search SUBJECT "newsletter"
* SEARCH 88 89 90 91 92
01 OK completed
01 uid search OR SUBJECT "field" SUBJECT "test"
* SEARCH 84 85 86 94 95 96 101
01 OK completed
01 uid search OR SUBJECT "field" (OR SUBJECT "test" SUBJECT "newsletter")
* SEARCH 84 85 86 88 89 90 91 92 94 95 96 101
01 OK completed
01 logout
* BYE CommuniGate Pro IMAP closing connection
01 OK completed


Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide