以下PowerShell命令发送电子邮件。如何在PowerBuilder中使用这些命令?
$EmailFrom = "frt@gmail.com"
$EmailTo = "ha@gmail.com"
$Subject = "Notification from XYZ"
$Body = "this is a notification from XYZ Notifications.."
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("frt@gmail.com", "mypass123");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
答案 0 :(得分:0)
您可能希望在旧的SAP PowerBuilder论坛上浏览Bruce Armstrong的this post。它显示了如何调用Powershell.exe并使其执行来自文本文件的命令。
答案 1 :(得分:0)
/// 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! )
答案 2 :(得分:0)
假设您能够用创建的包含命令的字符串替换点“ ......”,这是我使用的:
operator.gt
答案 3 :(得分:0)
针对特定问题的另一种方法是使用PowerBuilder的邮件功能。仅当您具有与MAPI兼容的客户端电子邮件时,它才有效:
DllImport