I am trying to make the bot read and download attachments from all the unread emails with a matching Subject however, it is giving me an error “Message: Cannot parse condition, Error at “(”. Exception type: System.Runtime.InteropServices.COMException”. Please find attached error screenshot.
The same program runs on a different email address but not working for the current one. Can someone help me figure out the issue. Thank you.
I guess mail is not of type System.Net.MailMessage. We are using this expression in Filter property of Get Outlook MailMessage Activity. It should be like this:
"[Subject] = ' subject of the mail ' "
If we store subject in a variable then we have mention like : varSubject.Tostring
@ClaytonM@lakshman I tried both ways but it’s still not working. It works fine for other email addresses but when I trying to use on my work email it doesn’t work.
sorry but it is not working. I tried yours and ClaytonM way also but still count is “0”.
without using filter it properly fetching mails.
correct me if i am doing wrong
Hmm, I’m not sure. Have you looked for similar issues on the forums?
It’s possible one of your Emails has a Subject that just doesn’t work with the filter. But, you can run the mailmessages variable through a For Each loop and check the subject of each one. You can also use .net to filter the mailmessages, but might be slower since it needs to get all emails up to your Top property.
Thanks @ClaytonM I have tried looking for similar issues on the forums but didn’t find any relevant post. I will try your this approach as well. Thank you so much for your help.
Why are you getting the MailMessages twice? Typically, you only get the MailMessages one time (possibly with a filter), then do something with it. However, you are trying to Get MailMessages for each individual mail message, which seems wrong to me. So I am asking if you have a reason for this.
Here are some additional suggestions as far as coding practices: mail.Subject.Contains("MetroFax") or mail.Subject.Contains("Metrofax") or mail.Subject.Contains("metrofax") or mail.Subject.Contains("METROFAX")
You can change this long condition simply by change the string to upper or lower case. mail.Subject.ToUpper.Contains("METROFAX")
much simpler
Also, it is good to use Path.Combine() when joining folders and filenames together. This is helpful, because you don’t need to worry about the ending slash mark. Secondly, use either Now or Today as your current DateTime so simplify things a bit System.IO.Path.Combine(folderPath, Today.ToString("MM-dd-yyyy")
I also usually suggest putting the year first in the date for folder and filenames, because it sorts better alphabetically. "yyyy-MM-dd" which will put 2019-07-03 above 2018-12-01, whereas, 07-03-2019 will be below 12-01-2018, even though it is a newer date
The Save Attachments looks good, but if you get an error on it, then you might need to check the attachment count beforehand, like If mail.Attachments.Count > 0
Other than that, I just don’t know why you have that second Get Mail Message step.
@ClaytonM Thank you for correcting me and I greatly appreciate your suggestions. The reason why I have used Outlook activity twice is because when I am trying to put the filter on the First outlook activity it is not working.
This is what I tried: “[subject]=‘MetroFax’”. But it didn’t return anything so I have used another outlook activity inside the loop to “mark as read” only those emails with “MetroFax” keyword.
Can you help me figure out how to make the filter work with just one Outlook activity?
Just out of curiosity, does the If Activity work correctly, like it’s finding the emails with ‘MetroFax’?
In order to troubleshoot the Filter property, you would want to look at the exact subject string and check its case. Because if you don’t want it case sensitive, you’ll need a different filter string. Also, I think the main issue is that you are using “=” so the subject is required to be exactly MetroFax. See if replacing the equals with “Like” works. [Subject] Like 'MetroFax'"
However, I’m not a big user of sql syntax like this, so I could be wrong on that. You want to filter if it contains ‘MetroFax’ and I think Like is the equivalent of that.
If you get the filter in the first one working, then you can remove the If activity.
@ClaytonM It didn’t work with this condition. Got an error ‘Invalid condition’. The if condition works fine but when trying to do through the filter property it doesn’t work.
If possible can you send me a working example relevant to what I am trying to achieve. As in making the bot read only emails with Subject ‘MetroFax’ and marking only those emails as read. Thank you and apologies for bothering you again.