Я использовал аналогичный подход, как указано в ссылке Мэтта.Это сработало для меня.
/// Powershell commands to send email with attachment are saved in a file and that file is given to
/// powershell executeable file as parameter
Integer li_FileNum
String theCmd
li_FileNum = FileOpen("C:\Temp\cmd.ps1", LineMode!, Write!, LockWrite!, Replace!)
theCmd = "$fromaddress = ~""+SendFrom.Text+"~""
FileWrite(li_FileNum, theCmd)
theCmd = "$toaddress = ~""+SendTo.Text+"~""
FileWrite(li_FileNum, theCmd)
///theCmd = "$bccaddress = ~""+"BCC"+"~""
///theCmd = "$CCaddress = ~""+"CC"+"~""
theCmd = "$Subject = ~""+Subject.Text+"~""
FileWrite(li_FileNum, theCmd)
theCmd = "$body = ~""+Msg.Text+"~""
FileWrite(li_FileNum, theCmd)
theCmd = "$attachment = ~""+TheFile.Text+"~""
FileWrite(li_FileNum, theCmd)
theCmd = "$smtpserver = ~"smtp.gmail.com~""
FileWrite(li_FileNum, theCmd)
theCmd = "$message = new-object System.Net.Mail.MailMessage"
FileWrite(li_FileNum, theCmd)
theCmd = "$message.From = $fromaddress"
FileWrite(li_FileNum, theCmd)
theCmd = "$message.To.Add($toaddress)"
FileWrite(li_FileNum, theCmd)
//theCmd = "$message.CC.Add($CCaddress)"
//FileWrite(li_FileNum, theCmd)
//theCmd = "$message.Bcc.Add($bccaddress)"
//FileWrite(li_FileNum, theCmd)
theCmd = "$message.IsBodyHtml = $False"
FileWrite(li_FileNum, theCmd)
theCmd = "$message.Subject = $Subject"
FileWrite(li_FileNum, theCmd)
theCmd = "$attach = new-object Net.Mail.Attachment($attachment)"
FileWrite(li_FileNum, theCmd)
theCmd = "$message.Attachments.Add($attach)"
FileWrite(li_FileNum, theCmd)
theCmd = "$message.body = $body"
FileWrite(li_FileNum, theCmd)
theCmd = "$smtp = new-object Net.Mail.SmtpClient($smtpserver)"
FileWrite(li_FileNum, theCmd)
theCmd = "$smtp.EnableSsl = $true"
FileWrite(li_FileNum, theCmd)
theCmd = "$smtp.Credentials = New-Object System.Net.NetworkCredential(~""+SendFrom.Text+"~", ~""+Password.Text+"~");"
FileWrite(li_FileNum, theCmd)
theCmd = "$smtp.Send($message)"
FileWrite(li_FileNum, theCmd)
FileClose(li_FileNum)
int li_rc
string ls_command
string ls_directory
ls_directory = "C:\temp"
ls_command = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "&'
ls_command += " '" + ls_directory + "\cmd.ps1' "
li_rc = Run ( ls_command, Minimized! )