How to compare two mailmessage variables

Hi,

Can someone please help me in how to check if both the mail message variables are same or not?

Thanks in Advance

hi @Konda_Sai_Charan_Goud

Welcome back to the forum!

I suppose you cannot directly compare it but can compare in parts by checking the
From, To, Cc, Subject, Body and attachment names.

Regards,
Aditya

You can check multiple things, from simple (but risky) ones, as they might generate false positives, to a bit more specific ones, but they might generate false negatives, youโ€™ll need to find the balance :slight_smile:

Example of easy one - Compare mail1.Subject.ToString to mail2.Subject.ToString, and you could also compare mail1.Body to mail2.Body.

  • This one is risky because they can share subject and body, and it might not be what you need to identify as โ€œequalโ€
  • Use String.ToLower.Equals, as it will be safer.
  • mail1.Subject.ToString.ToLower.Equals(mail2.Subject.ToString.ToLower)

If you want to check not if the content is the same, but if indeed we are talking about the same mailmessage variable, you can use the Unique ID Header from both emails, as it should tell you if you have exactly the same mailmessage in both variables:

  • mail1.Headers(โ€œUIDโ€).ToString.Equals(mails.Headers(โ€œUIDโ€).ToString)

Hope this helps!

BR,
Ignasi

@Konda_Sai_Charan_Goud,

Welcome to the UiPath Community!

You can accomplish this using If Activity.

In Condition put like this.
mailMessage1 = mailMessage2

Thanks,
Ashok :slight_smile:

Not sure if โ€œ=โ€ would work for System.Net.Mail.MailMessages variables, might be wrong thoโ€ฆ


image

BR,
Ignasi

@Konda_Sai_Charan_Goud/@ignasi.peiris

May be try this one.

image

Thanks,
Ashok :slight_smile:

1 Like