Send-mailmessage vs. smtpclient.send()


hi, have script massively uses send-mailmessage.
far worked great, because internal mailserver used, allowed anonymous logins.

now, need switch external mail server requires smtp-authentication. reason credential parameter of send-mailmessage not seam work in way sever requires.

i got work smtpclient.send() (see below) rather use send-mailmessage, because otherwise need change lot of code , test it... etc.
there way work?

thanks, rob

# this works: #-------------   $subject = "poshmailtest" $body =  "test" $emailto = "othermail@somewhere.com" $emailfrom ="mailaccount@gmx.net" $smtpserver = “mail.gmx.net” $smtp = new-object net.mail.smtpclient($smtpserver) $credentials=new-object system.net.networkcredential(”mailaccount@gmx.net”,”mypassword”) $smtp.credentials=$credentials.getcredential($smtpserver,"25","basic") $smtp.send($emailfrom, $emailto, $subject, $body)   # this doesn't: #--------------    send-mailmessage -subject "posh mailtest"  -body "test" -from mailaccount@gmx.net -to othermail@somewhere.com -credential (get-credential) -smtpserver mail.gmx.net      # errormessage:   [...] server answer: 5.7.0 need authenticate via smtp-auth-login {mp012} [...] 



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file