そのため、何度でも呼び出すことができる暗号化された文字列をテキスト ファイルに保存しています。これが SMTP スマート ホストのパスワードです。これは次の方法で作成されます。
Read-Host "Enter the Password:" -AsSecureString | ConvertFrom-SecureString | Out-File C:\EncPW.bin
$username
これをaとともに何らかの形で関数の-Credential
パラメーターに渡す必要がありSend-MailMessage
ます。これを PSCredential 形式にする必要があると思います。しかし、私は立ち往生しています!
$password = cat C:\encPW.bin | ConvertTo-SecureString
$password
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username,$password
今のところ私はこれを持っていますが、印刷すると $password が出力System.Security.SecureString
され、エラーが発生します:
net_io_connectionclosed
SMTP送信しようとすると。
乾杯
CALL to SMTP 送信:
Send-MailMessage -from "TestPS@mydomain.co.uk" -To "someone@mydomain.co.uk" -Subject "Daily Report" -Body "Open Attachment for Report" -smtpServer 85.119.248.54 -Attachments "C:\WSB_Reports\DailyReport.txt" -Credential $cred