O365 Exchange sendmail to myself

New here and I wonder how to send an O365 email to myself without hardcoding my email address in the sendmail activity.

The activity is able to default the from as being myself so there must be an regular expression I could use for the To:

Is there anybody who can advise ?


What you are looking for is to use a variable :slight_smile: But please do take into consideration that the O365 send mail message accepts an array of strings as input for the To email field


Thanks Drago, need to figure out how to update the variable dynamically identifying the email of the O365 user running this automation… and I’m a Studio X user so not sure I can work with variables and VB scripts

only thing I can think of is using the “Save for later” activity, I can create a variable but I don’t know how to retrieve dynamically the email of the O365 user running the automation to populate the variable in the Expression Editor


Hmmm … really do not know , but frankly i think that you are approaching this based on the assumption that windows username == email address which is prone to generating more issues that it solves.

For example the following VB functions:

  • Environment.UserName – will return the username of the user which is running StudioX .

  • System.Security.Principal.WindowsIdentity.GetCurrent().Name – will retrieve the username and the domain

Another approach would be to use an input dialog, and ask the user at runtime to provide his email address :slight_smile:

Hope this helps,

Many Thanks Dragos,

Yes we are progressing in the right direction I believe.

As a matter of fact when using the SendMail Activity, I don’t need to confirm who is the sender and it will automatically send the email using my O365 credentials.

This works well as a built-in feature for the “From” but you are forced to hardcode a value for the “To” which defeats the purpose for me as with StudioX I want to be able to develop an automation that can be deployed for many attended users. In this particular case, this is an attended automation that scraps some information from multiple sources and format them in an html email to myself.

This is the reason I’m trying to find a way to retrieve this email address that was used automatically for the “From” as I want to have it for the “To” as well.

Are your email addresses always the username@yourcompany.com?

If so, then…

Environment.UserName + “@yourcompany.com

…will result in the email address you want.

Nice … although my username is a meaningless code that is different from my email and domain differs from country to country … this won’t work unfortunately. I believe the information I’m looking for must be accessible since the “sendmail” activity can connect to my mailbox and send emails on my behalf that I see afterward in my “Sent” box. It is just that I cannot build an automation to send email to myself without hardcoding my email as the recipient of the email …

Just for completeness, I’m using Microsoft O365 and for this I had to register UiPath in our O365 Tenant.