Unable to find attachment count - outlook message.Attachments.Count is always 0


#1

I have emails with attachments, but when I use the message.Attachments.Count (or message.Attachments.Any) I always get 0 as the count.

Here is my code and screenshots to explain further:

Email is an exchange account, Outlook is 2016 32 bit, OS is Windows 10 64 bit.

Here is an example project I made to demonstrate my problem:

project.json (305 Bytes)
Main.xaml (6.1 KB)


#2

Hi @djorchard,

Please try this code in message box.
item.Subject.ToString()+"&"+item.Attachments.Count.ToString()

Regards,
Arivu :slight_smile:


#3

Thanks for the reply Arivu.

Unfortunatly using ToString() provides the same result (0 attachments)

image


#4

Make sure that you are using typeargumenttype in foreach should be system.net.mailmessage.


#5

thanks, yes I am using system.net.mailmessage
image

I know it is talking to the email because it obtains the subject (please see the message box text with the subject “test 123”) but it just doesn’t return the attachment count.

If you use my code in the initial post, and create a folder test under your inbox, with an email with an attachment, what does your script say? Is this a bug? or is it only happening to me?

I have tested this on another 2 computers, with different email accounts, and all computers show 0 as the attachment count when the email has an attachment…

I am trying to write a script that will process emails with attachments, but it needs to first verify there is an attachment (if there isn’t put the email in cannot process folder due to missing attachment) but I have no way to check if there is an attachment. Any suggestions?


#6

I’m not sure and have not tested .Attachments.Count on my end, however, you could try using “Save Attachments” and use the Output property to store them to a list. Then you can just do list.Count.ToString

If that doesn’t work, then I have no idea what you can try other than that.


#7

Thanks for the reply Clayton,

The plot thickens.
I can get the message subject,
but I cannot get .attachments or .body
When I run Save attachments, it doesn’t save any attachments, and when I tried your suggestion it tells me the count is 0 in the outputted list.
I am going to now try on another computer with a different email account type (POP3) to see if it is perhaps a security issue with my work computer…


#8

OK, an update after testing.
works fine on a gmail account,
doesn’t work (0 attachments, no body) on an Exchange account…


#9

Another update for anyone else who encounters the same issue:

I couldn’t solve this issue after several hours trying,

So I used the workaround of using the Get Exchange Mail Message instead of Get outlook mail message.
(I prefer Get outlook as it is instant, Get Exchange takes about 60 seconds on my computer, likely because my exchange server is on the other side of the world…)


#10

To close this off, my issue turned out to be a security/group policy that my company uses. I don’t know what the policy is, but I found that using a computer with security policies turned off worked…