rbaggett
rbaggett

Reputation: 21

Exception calling "send" with "1" argument(s): "A recipient must be specified"

param ([switch]$configure)

$Date = Get-Date

$Server = gc env:computername

Create e-mail message

$msg = new-object Net.Mail.MailMessage

Set e-mail properties

$msg.subject = $Subject

Set e-mail body

$msg.body = $Body

Creating SMTP server object

$SMTP = new-object Net.Mail.SmtpClient($SMTPServer)

Email structure

$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

Answers (1)

vrdse
vrdse

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

Related Questions