PowerShell configure smtpserver
in powershell how configure smtpserver:
ping "stmp.email.com" = “xxx.xx.xx.xxx” $smtpserver = “xxx.xx.xx.xxx” or "stmp.email.com"????????
ps code:
$ipsmtp = 'xxx.xx.xx.xxx' $plainpassword = "adminpassword" $securepassword = $plainpassword | convertto-securestring -asplaintext -force $username = "mysite\administrator" $credentials = new-object system.management.automation.pscredential -argumentlist $username, $securepassword $mailprops=@{ subject = 'this subject' body = 'the body , subbody' to = 'emailto@mail.com' from = 'emailfrom@email.com' smtpserver = 'smtp.email.com' } send-mailmessage $mailprops -credential $credentials
no matter if use smtpserver: 'smtp.email.com' or $ipsmtp still same result.
this ps code missing credentials for'smtp.email.com'. has username , password associated enter it.
error code:
send-mailmessage : the specified string not in form required for e-mail address. at c:\users\administrator\documents\ps\email.ps1:14 char:1 + send-mailmessage $mailprops -credential $credentials + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidtype: (:) [send-mailmessage], formatexception + fullyqualifiederrorid : formatexception,microsoft.powershell.commands.sendmailmessage send-mailmessage : the email cannot sent because no smtp server specified. you must specify smtp server using either smtpserver parameter or $psemailserver variable. at c:\users\administrator\documents\ps\email.ps1:14 char:1 + send-mailmessage $mailprops -credential $credentials + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidargument: (:) [send-mailmessage], invalidoperationexception + fullyqualifiederrorid : microsoft.powershell.commands.sendmailmessage
hi philosophiae,
you trying use splatting specify parameters, have minor typo in there:
# typed send-mailmessage $mailprops -credential $credentials # should have typed instead send-mailmessage @mailprops -credential $credentials
cheers,
fred
there's no place 127.0.0.1
Windows Server > Windows PowerShell
Comments
Post a Comment