Reputation: 21
param ([switch]$configure)
$Date = Get-Date
$Server = gc env:computername
$msg = new-object Net.Mail.MailMessage
$msg.subject = $Subject
$msg.body = $Body
$SMTP = new-object Net.Mail.SmtpClient($SMTPServer)
$msg.From = "[email protected]"
$msg.Replyto = "[email protected]"
$Subject = "Hardware Alert from $Server $Date"
$SMTPServer = "smtp.office365.com"
$SMTPPort = '25'
$SMTPUser = '[email protected]'
$SMTPPassword = 'password'
body
else{$smtp.Send($msg)}
I keep getting "a recipient must be specified" when I run this. What am I doing incorrectly?
Upvotes: 1
Views: 2492
Reputation: 3154
I keep getting "a recipient must be specified" when I run this. What am I doing incorrectly?
You did not specify a recipient. (There is no one who could receive that mail.)
The MailMessage
class not only has a From
property, but also a To
property.
$msg.To = "[email protected]"
Check out the documentation at https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage(v=vs.110).aspx
Upvotes: 1