Powershell sends emails through SMTP, powershellsmtp

Source: Internet
Author: User
Tags mailmessage

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.

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.