Sending an email using PA on IBM Cloud

Post Reply
Adam
Posts: 124
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.x
Excel Version: Microsoft 365 x64

Sending an email using PA on IBM Cloud

Post by Adam »

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!
I've started blogging about TM1, check it out: www.havaslabs.com

Take care,
Adam
User avatar
gtonkin
MVP
Posts: 1261
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Sending an email using PA on IBM Cloud

Post by gtonkin »

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.
BR, George.

Learn something new: MDX Views
Adam
Posts: 124
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.x
Excel Version: Microsoft 365 x64

Re: Sending an email using PA on IBM Cloud

Post by Adam »

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.
I've started blogging about TM1, check it out: www.havaslabs.com

Take care,
Adam
User avatar
yyi
Community Contributor
Posts: 122
Joined: Thu Aug 28, 2008 4:42 am
Location: Sydney, Australia

Re: Sending an email using PA on IBM Cloud

Post by yyi »

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 '","')
Yeon
Post Reply