Page 1 of 1

Sending an email using PA on IBM Cloud

Posted: Wed Jun 17, 2020 2:07 am
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!

Re: Sending an email using PA on IBM Cloud

Posted: Wed Jun 17, 2020 2:54 pm
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.

Re: Sending an email using PA on IBM Cloud

Posted: Wed Jun 17, 2020 3:52 pm
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.

Re: Sending an email using PA on IBM Cloud

Posted: Tue Mar 30, 2021 6:12 am
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 '","')