pwsh -Command 'Send-MailMessage -SMTPServer localhost -Port 25 -To testuser@localhost -From youremail@domain.com -Subject "This is a test email" -Body "test body"
// в консоле отправляется нормально
pwsh = "pwsh"
command = "-Command 'Send-MailMessage -SMTPServer localhost -Port 25 -To " + recipient + " -From " + user.Email + " -Subject \"" + subject + "\" -Body \"" + message + "\"'"
output, err := exec.Command(pwsh, command).Output()
// результат: как будто просто написал pwsh
// exit status 64
// 2020/05/05 01:33:48
// Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
// [-Command { - | <script-block> [-args <arg-array>]
// | <string> [<CommandParameters>] } ]
// [-ConfigurationName <string>] [-CustomPipeName <string>]
// ...
pwsh = "pwsh"
command = []string{"-Command", "Send-MailMessage -SMTPServer localhost -Port 25 -To " + recipient + " -From " + user.Email + ` -Subject "` + subject + `" -Body "` + message + `"`
output, err := exec.Command(pwsh, command...).Output()