How to get mail.To email address only and not the display name

Hi, I am trying to use mail.To to get the email address of the email recipient. However, I get it in a format which has the display name as well. How can I format it to only give me the email address?

1 Like

use properties like yourtemailvarible.to it will give you to address.

Hi @darshini
You can use yourMailMessageVariable.Sender.Address to get email address only.

Cheers!

2 Likes

I used mail.To but the value comes as ‘Displayname’ username@xxxxxx.com in excel rather than just username@xxxxxx.com

mail.Sender.Address won’t work as it will give me the sender address but i need the recipients address

@darshini
In that case, you have to use regular expression or string manipulation.
If you use regex then follow below steps:-

  1. Use Assign activity - MailAddress = System.Text.RegularExpressions.Regex.Match(ToMailVariable,“([\w.-]+)@([\w-]+)((.(\w){2,3})+)”)
  2. Now print MailAddress it will give you only mail address without Display Name.

I hope it’ll help you.

1 Like

Mail.To is collection of emails

You can use:
Mail.To(0).Address for getting first recipient email,
Mail.To(1).Address for getting second recipient email, and so on.

The easiest way, just use for each to iterate each mail address in Mail.To

3 Likes

Hi I tried the above and it works :slight_smile: Thanks a lot!!

1 Like

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