Sending an email via Powershell

Hi all

I have to send emails via Powershell (the Send Mail activity isn’t an option, as I’m using an old version of UiPath Studio which doesn’t support the activity), and I’ve never used Powershell before. I have the code and can invoke it, but there’s one thing I can’t work out.

The process is: download a load of PDFs, read through them one by one to find an account number. If the account number is between 1-5, it’ll send the PDF in an email to account holder from the email address 1@email.com. If the account number is between 6-10, it’ll send the email from 2@email.com, and so on.

The thing I can’t work out is how to change the subject of the email (which will be the account number, so this will be different for every email), how to change the recipients email address, and how to change the body of the email, as these are all hard written into the .txt Powershell code.

Can anyone help please?

Thanks :slight_smile:

Hey @Short

You need to make it dynamic either from powershell script or to pass that data from UiPath to powershell.

Hope that helps

Thanks
#nK

Wait, how old is the studio version to not support send mail? You could always install a version of the mail package that fits your UiPath version

But if that’s really what you need, here’s an useful resource:
Send-MailMessage (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

Also, as @Nithinkrishna said you need to define parameters in your powershell script
about Parameters - PowerShell | Microsoft Docs

1 Like

Hi @Nithinkrishna :slight_smile:

Thanks for the reply. How would I pass it through? That’s the thing I don’t understand as the Powershell is invoked through a .txt file

Thanks

You are reading the script from text file and running it through invoke powershell is that correct ?

Hi @Edwin_Barahona

Haha it’s old! 2019.4.4 I think, unfortunately as it’s through work they need to agree with other clients who use UiPath that it can be upgraded.

Thank you :slight_smile: I’ll look at these tomorrow

Hello @Short

If you want to dynamically pass a variable you can create powershell variables in the powershell variable field. Then you can add those same variables in the text file as well.

For example if the powershell variable declared is emailId, use that in the text file as $emailId.

Thanks, if that’s a requirement not to use it for any kind of concern, then it is what it is, but sometimes restrictions are dumb and we may only be afraid to ask why?

FYI, You can still explore using UiPath.Mail.Activities 1.4.0 should be more than safe for your studio version, I believe what you’re looking is to send email through SMTP. Hope you can solve it.

As far as my memory recalls (working with UiPath since 2017) Mail.Activities package was always part of the standard installation and it always contained “Send SMTP Mail Message” activity.

Also the package version is process dependent so you are quite free to choose Mail.Activities package version.

Using powershell for this purpose seems quite obscure :slight_smile:

Cheers

Hi @J0ska and @Edwin_Barahona

I agree, using Powershell does seem obscure and it isn’t my first choice to use it. However, whenever I try to use the Send Mail activity I get this error:

image

One of the support team in work looked into it and advised that it was due to UiPath needing to be upgraded to version 2019.4.6+. I also have been working with UiPath since 2017 and have always used this activity without any issues, but figured they might be trying to get people to upgrade versions and maybe phasing things out?

The MailActivity package is version 1.4.1:

If anyone has any suggestions on how to overcome the above error, I would be eternally grateful

Thanks

Hi @Nithinkrishna

That’s correct, it’s currently looking like this:

image

Did you try update the Mail.Activities package to some later version?
According release notes in v1.6.0 there was some TLS related fix.
I would recommend upgrade Mail.Activities package step-by-step until works.
Cheers

Hi @J0ska

The update button is greyed out, do you know how I’d get around this? I’ve uninstalled and reinstalled it but got the same version, and 1.4.1 is the only version available on the drop down menu

First you have to select new version. It will enable the “Update” button.

But strange is that the update option doesn’t show in your list.

It looks like you have no access to Official package source - or not configured propperly
image

Cheers

1 Like

Hey @Short

The screenshot make sense and we are almost done.

Now it’s time to show us the script part where you want to pass the path dynamically please ?

Thanks
#nK

Actually, you’re down for just 1 version according to this article TLS 1.2 support was introduced in 2019.10

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