How to get outlook email subject into string variable

I have been trying to assign an email subject to a string variable

I am using the assign function to say

mail.subject is assigned to variable1

however it doesnot seem to be able to capture this…


It should work for string assignment.Are you getting any error? Can you paste screenshot of your code?

1 Like

this is the code
thanks for your help.
when I print it in msgbox to see …it is not showing anything…
I also wanted to do some string oeprations such as substring to it but doesn’t seem to work…
interestingly… mail.subject.contains() works for me though…

1 Like


you have it reversed, ‘mail.subject is assigned to variable1’. In your example you are assigning variable(userwithresponse) to mail.subject.



How to save( All Mail subject) in excel ?

Do a foreach loop for all the mails. For each mail add a mail.Subject to a Datatable as a new row, append Datatable to an excel.


1 Like

Hi @neerajmca5,

Refer this Post,

Please try to avoid creating duplicate post.


can you share xml
Am getting error

1 Like

Hello everyone, I am trying to get subject of mails iteratively in for each loop
I tried for outlook and IMAP both but not succeeded in both cases

mailActivity.xaml (8.7 KB)
mail_reply.xaml (8.6 KB)

in case of Get Outlook mail message the exception is coming “The specified folder does not exist” I have specified “Inbox” under input MailFolder field, and tried allomost all other solutions given on net like remove emailId from account field and by removing “Inbox” from MailFolder, by running outlook as administrator etc but not succeeded.

In case of IMAP the mail.Subject/mail.subject is throwing compiletime because subject is not applicable/accessible on mail variable which is in forch each loop like (ForEach mail in mailsList)

I checked the type of mail which is System.Net.Mail.MailMessage
what i’m doing wrong? what is the solution of this problem, help is highly appreciable.
i’m sending my XAML file for better understandin

I solved it by specifying for Each activity Misc Type Argument as System.Net.Mail.MailMessage. :slight_smile:

1 Like

Hi Edgars,
I have attached XAML for the same, only change is i’m using IMAP instead of outlook, but not an issue you can just replace the IMAP with outlook.
Note: you have to assign MailsList as a System.Collections.Genric<System.Male.MaleMessage> variable type
and for loop Type Argument as System.Male.MaleMessage
ask me if you are facing any issue further
ReadMail.xaml (6.2 KB)

1 Like

I have specified Inbox is my folder but it shows the below exception,

Source: Get outlook mail messages
Message: The specified folder does not exist
Exception Type: ArgumentException
System.ArgumentException: The specified folder does not exist
   at UiPath.Mail.Activities.GetMailActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
1 Like

I want to extract the subject from each mail the bot reads and then make it to lowercase.
The only error I am facing is that, it is not accepting mail.Subject.ToString in the assign activity, kindly correct me.Thank you

1 Like

Hello, well I am trzing to do the similar thing but for me its showing a validation error.
maz be any of u can guide me a bit…

how to add email metadata into datatable
datatable columns : subject(String), body(String), attachmentName(String)