Powershell sends emails through SMTP, powershellsmtp
The. net method has been used for sending emails for a long time. It is easy and error-prone because of the built-in powershell method. Recently, some people have encountered problems in using it.
# Define the function sendmail ($ mailaddr, $ body) {$ msg = New-Object System. net. mail. mailMessage $ msg. to. add ($ mailaddr) $ msg. from = New-Object System. net. mail. mailAddress ("email sending account @ xxx.com", "display name", [system. text. encoding]: GetEncoding ("GB2312") $ msg. subject = "title" $ msg. subjectEncoding = [system. text. encoding]: GetEncoding ("GB2312") $ msg. body = $ body # $ Attachments = New-Object System. net. mail. attachment ("D: \ Documents ents \ xxxx . Zip ") # create an attachment # $ msg. Attachments. add ($ Attachments) # add an attachment. Multiple English names can be added, and only one Chinese name can be included. $ Msg. bodyEncoding = [system. text. encoding]: GetEncoding ("GB2312") $ msg. isBodyHtml = $ false # Send an html-format email # $ msg. priority = [System. net. mail. mailPriority]: High $ client = New-Object System. net. mail. smtpClient ("SMTP address") $ client. useDefaultCredentials = $ false $ client. credentials = New-Object System. net. networkCredential ("account @ xxx.com", "password") try {$ client. send ($ msg)} catch [Exception] {$ ($ _. exception. message) $ mailaddr }}# send email sendmail $ mailaddr $ body
Zookeeper
An issue with sending emails using powershell
First, check whether smtp is enabled for your QQ mailbox. It is generally set in the background.
In addition, try the "Send-MailMessage" command.
For smtp mail sending Problems
Do you send emails using the command line method? You connect to the mail server to send emails. You are the client, and the server is the server.