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} [...]
you surely find answer here:
http://stackoverflow.com/questions/1252335/send-mail-via-gmail-with-powershell-v2s-send-mailmessage
Windows Server > Windows PowerShell
Comments
Post a Comment