PowerShell sends mail via SMTP

Source: Internet
Author: User
Tags mail account

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.