Check if an email has been sent out

email

#1

Hello everyone I would like to check if an emial has been sent out, it has a structured subject so I tried to do it with get outlook message activity and a for each but I don’t know where to go after that… any Ideas?
I would like to get the date and hour that it was sent and put into an excel file, I know the excel part but don’t know how to get the mail details. I’ve change the folder from inbox to “Éléments envoyés” (in french for sent emails) and I see UiPath running on them but don’t know how to get the details.

many thanks


#2

Hi,
You can try this syntax inside for each loop
item.Headers.Item(1).ToString

Note: I don’t know index “1” is for date and time,Coz from index 1-3 its give date and time.
Hope so this will help you.

Thanks.


#3

Indexes are:
0 - Uid
1 - Date
2 - DateCreated
3 - DateRecieved
4 - HtmlBody
5 - Size

You can use them either by numeric index or name (item.Headers(“DateCreated”)). Note: it always returns a string (at my settings it’s with invariant format, so 11/04/2016 09:29:21 as an example of an email from today). If you want a “real” date, you’ll need to parse it.

You can get the headers names by using item.Headers.AllKeys (returns a String array with all headers names).
Note that in some circumstances, some of the headers might be null, so if you have doubts, always check with String.IsNullOrEmpty(yourValue).

Regards/


#4

Hello Dear friends, I have found a solution. <lml

Create a variable (mailMessages) to store the email list. The type should be: system.collections.generic.list < system.net.mail.mailmessage>

the value I was looking for I was able to find it in mailMessages(COUNTME).Subject

then for each item in mail messages (“Sent” folder already set on the properties pane) you need to initialize a counter to iterate in all the email list and sum 1 at the end (a counter… daaa)

Need help let me know. :slight_smile:


How to add the sender name, email address and Attachment name to an excel?
#5

Hello And thank you for your reply, I was trying to get the senders email address now, I am able to get the first one but the second email on the list I can’t. Can you please take a look of this simple xaml ? Email properties .xaml (14.2 KB)


#6

Hi,

First off - you don’t need a counter in a foreach loop.
Whenever you use “mailMessages(countme)” you can substitute it with “item” (the name of the variable you’re using in the for each).
To make it work properly, from ForEach properties change TypeArgument to system.net.mail.mailmessage.
As a rule of thumb, you almost never want to use Object as the TypeArgument in a for each, unless you’re working with non-generic collections (which is also very rare :slight_smile: ).

I don’t quite understand the question - as far as I’m aware there’s always only one sender address (unless I’m missing something). Maybe you meant ReplyToList or CC?

Either way if a property returns more than one address, it uses MailAddressCollection. You can iterate over it also using ForEach.
Attached very short sample that should get you in the right direction.

One last sidenote - consider avoiding variable names in all upper (COUNTME). In .Net naming convention that’s used for constants and can thus create misunderstandings.

Email properties .xaml (14.1 KB)


#7

Thank you Andrzej, I guess there is an issue with my uipath it is throwing an error “Write line : Object reference not set to an instance of an object.” on the writeline for “Item.from.address”

:frowning:


#8

I don’t think that’s an error in UiPath.
Can you find that email and see what it should have as the From? If you didn’t modify the workflow I’ve attached, Subject was printed first, so it shouldn’t be hard.
Does it replicate every time you run? Is it all emails or just this particular one?

If I understand the class correctly, sender info will be null until actually sent, but after that it should always have something. Are you still getting emails from the SentItems folder?

If you can’t locate the cause, wrapping it in Try/Catch might be warranted (well, it’s a good idea anyway) just to be on the safe side.


#9

You know what is weird, is that if I type (inside the for each) item and then “dot” it doesn’t shows me the properties of the mail item, just to string get type, etc… on the other hand if I type it uipath says "option strict on disallows late binding or if I create a new workflow and read the emails and create an output list says that I cannto convert object to string. if I use item.string it says that I cannto convert string from system.net.mail.mailmessage :frowning:


#10

Check the variable type of your for each loop and change it to System.Net.Mail.MailMessage.
From what you’re describing it’s set as System.Object which would make the errors correct.