Sending an email using PA on IBM Cloud

Post Reply
Adam
Posts: 42
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.4
Excel Version: Office 365 x32

Sending an email using PA on IBM Cloud

Post by Adam » Wed Jun 17, 2020 2:07 am

I was reading a recent thread and found out about sending an email using SMTP PA on IBM Cloud.

I have a working prototype and I figured I would share the two quick little EXPANDABLE scripts that I wrote. Spent (<2 hrs) on it so of course not optimized.

PowerShell Script: email.ps1

Code: Select all

[System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'

$emailFolder = $args[0]
$emailID = $args[1]
$emailSubject = Get-Content -Path $emailFolder\email$emailID.txt | Select-Object -Index 0
$emailBody = Get-Content -Path $emailFolder\email$emailID.txt | Select-Object -Index 1

$sendMailParams = @{
    From = 'xxxxx@mail.planning-analytics.ibmcloud.com'
    To = 'youremail@domain.tld'
    Subject = $emailSubject
    Body = $emailBody
    BodyAsHTML = $true
    SMTPServer = 'mail.planning-analytics.ibmcloud.com'
    Port = '587'
    UseSsl = $true
    Encoding = ([System.Text.Encoding]::UTF8)
}

Send-MailMessage @sendMailParams
TI Process:

The TI Process takes two (hopefully self-explanatory) parameters:
  • pEmailSubject
  • pEmailBody - Can be HTML

Code: Select all

sEmailFolder = 'S:\prod\tm1\Email';
sEmailScript = 'email.ps1';
sEmailScriptPath = Expand('%sEmailFolder%\%sEmailScript%');

sEmailID = TimSt(Now(), '\Y\m\d\h\i\s');

sEmailFile = Expand('email%sEmailID%.txt');
sEmailFilePath = Expand('%sEmailFolder%\%sEmailFile%');

DatasourceASCIIQuoteCharacter = '';
DatasourceASCIIDelimiter = ' ';

ASCIIOutput(sEmailFilePath, pEmailSubject);
ASCIIOutput(sEmailFilePath, pEmailBody);

If(FileExists(sEmailScriptPath) = 0);
	ProcessError();
EndIf;

ExecuteCommand(Expand('Powershell %sEmailScriptPath% %sEmailFolder% %sEmailID%'), 0);
TI creates a file so I don't have to worry about needing to escape white space, special chars, etc. Also I have no need for attachments so not yet implemented but not too complex using the IBM documentation on this very topic.

Good luck!
Take care.
Adam

User avatar
gtonkin
MVP
Posts: 900
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: PAL 2.0.9.4; PAoC 2.0.9.3
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Sending an email using PA on IBM Cloud

Post by gtonkin » Wed Jun 17, 2020 2:54 pm

Thanks Adam, have included a link to this thread from my PA readiness thread.
p.s. Thread may not be available to all users at this time.
Last edited by gtonkin on Thu Jun 18, 2020 10:16 am, edited 1 time in total.

Adam
Posts: 42
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.4
Excel Version: Office 365 x32

Re: Sending an email using PA on IBM Cloud

Post by Adam » Wed Jun 17, 2020 3:52 pm

Thank you! Just curious is that PA readiness thread in a forum I don’t have access to because I get an: You are not authorised to read this forum.-message.
Take care.
Adam

User avatar
yyi
Community Contributor
Posts: 121
Joined: Thu Aug 28, 2008 4:42 am
Location: Sydney, Australia

Re: Sending an email using PA on IBM Cloud

Post by yyi » Tue Mar 30, 2021 6:12 am

for multiple recipients, using $recipients = "email1@domain.com", "email2@domain.com" like in:-
https://www.ibm.com/support/pages/plann ... ell-script
if it doesn't work, then in .ps1 got this to accidently work;

[array]$emailTo = $args[0].Split(";")

instead of:-

$emailTo = '"{0}"' -f ($emailTo -join '","')
PA 2.0.62.6, win10, excel 365 x86

Post Reply