Save Attachment Activity is failing with " Object reference not set to an instance of an object."

Hi,

I am trying to save the attachment from mailMessages List, it is failing at Save Attachment activity, I checked my mailMessages it has emails with attachments. I am using Get IMAP MailMessages. Please help me.

1 Like

No worries
Can I have a view in the workflow a simple screenshot if possible
I hope there is no mails even fetched
Use a write line before for each loop like this
Mailmessagevariable.Count.ToString

This would give us the count of the mails fetched

Cheers @VGtha

1 Like

Yes Sir, I checked with debug mode, I can see one mail with attachment .
And the checked the Count also, And it is displaying the Count 1

Fine
may i know what is the assign activity used before for each loop
kindly make sure that mail has attachment and the type argument of for each loop in the property panel is System.Net.Mail.MailMessage

if possible can i have a view on the assign value in the assign activity
Cheers @VGtha

1 Like

Yes I am using the same type System.Net.Mail.MailMessage

GetMailMessages=GetMailMessages.AsEnumerable().Where(Function(x) x.Subject.ToString.Equals(“Subject”)).ToList

1 Like

Fine
everything looks good
lets check whether its geting mail with attachment or not
use a writeline activity and mention like this inside the for each loop activity
Mail.Attachments.Any.ToString
if true its good
else lets see
Cheers @VGtha

1 Like

is it showing any boolean value
Cheers @VGtha

1 Like

Sorry was away from desk, Yes it is giving the same error Object reference not set for write Line

double checked my Mail type and GetMailMessages type are system.net.mail.mailmessages and List

1 Like

The only thing that we are left with is the subject filter
Instead of using that expression let’s try with a simple way of approach
—like get the output From the get IMAP mail message activity and Pass it as input to for Each loop activity directly without the assign activity with that expression
—now with same argument type in the for each loop property panel
—Inside the loop use a if condition like this
Mail.Subject.ToString.Contains(“your subject”)
If the condition is true then it will go to THEN apart where we can have our SAVE ATTACHMENT activity
Or it will go for ELSE part where we can leave it empty without any activity

Hope this would work for sure
Cheers @VGtha

1 Like

@Palaniyappan I tried the same steps first time, But got compiler error, then i was using the Assign activity to filter mails.

I am not sure what was the mistake, But it is working after writing the same code in new process. Thank you @Palaniyappan

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.