E-Mail has been sent in. NET mode. Easy error due to the way PowerShell comes in. And relatively simple, recently seen some people also respond to the use of trouble.
#定义函数function SendMail ($mailaddr, $body) {$msg =new-object system.net.mail.mailmessage$msg.to.add ($mailaddr) $msg. from = New-object System.Net.Mail.MailAddress ("Send mail 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\xxxx.zip") #创建附件 # $msg. Attachments.Add ($Attachments) #加入附件. English names can be more than one. Chinese name can only bring one. $msg. bodyencoding = [System. Text.encoding]::getencoding ("GB2312") $msg. isbodyhtml = $false # $msg to send an HTML-formatted message #. 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 }} #发送邮件sendmail $mailaddr $body
??
PowerShell sends mail via SMTP