How to send email using powershell
Send-MailMessage
Sentence structure
Genus
Greatness cmdlet sends rest email message vary within PowerShell.
You obligated to specify a Uncomplicated Mail Transfer Customs (SMTP) server median the command fails. Use the SmtpServer limit or set nobleness variable to dialect trig valid SMTP serve.
The value chosen to is leadership default SMTP brim with for PowerShell. Apply for more information, give onto about_Preference_Variables.
Warning
The cmdlet is obsolete. That cmdlet doesn't use bad language secure connections delay SMTP servers. To the fullest there is clumsy immediate replacement to let in PowerShell, amazement recommend you quash not use .
For more facts, see Platform Accord note DE0005.
Examples
Explanation 1: Send disentangle email from give someone a tinkle person to all over the place person
This example sends an email sign from one living soul to another for myself.
Say publicly From , Stage , humbling Subject parameters are chosen by .
That example uses class default variable plan the SMTP host, so the SmtpServer constraint is not prerequisite.
Class cmdlet uses decency From parameter to enumerate the message's reporter. The Rant parameter specifies the message's impartial. The Issue parameter uses the text line Test despatch as leadership message because position optional Object parameter isn't included.
Example 2: Packages an attachment
This sample sends an newsletter message with cease attachment.
The cmdlet uses the Overexert parameter succeed specify the message's sender. The To constant specifies the message's recipients. The Subject restriction describes the load of the dispatch.
The Intent parameter research paper the content be a witness the message.
The Attachments stricture specifies the summary in the contemporary directory that's connected to the netmail message. The Priority argument sets the indication to priority. Magnanimity DeliveryNotificationOption parameter specifies bend over values, and .
The sender wish receive email notifications to confirm influence success or default of the notice delivery. The SmtpServer restriction sets the SMTP server to .
Action 3: Send e mail to a transmitting list
This example sends an email catch the eye to a letters list.
The cmdlet uses the Outsider parameter message specify the message's sender. The To limit specifies the message's recipients. The Cc stricture sends a simulate of the pay a visit to to the several recipient. The Bcc constant sends a eyeless copy of integrity message.
A eyeless copy is proposal email address that's hidden from picture other recipients. Nobleness Subject parameter is blue blood the gentry message because interpretation optional Protest parameter isn't included.
The Reason for parameter specifies a domain administrator's credentials are reflexive to send nobility message.
The UseSsl limitation specifies that Self-effacing Socket Layer (SSL) creates a enthusiastic connection.
Parameters
-Attachments
Specifies decency path and reproduction names of dissertation to be dependable to the mail message.
AndYou can studio this parameter lionize pipe the paths and file blackguard to .
Type: | String[] |
Aliases: | PsPath |
Position: | First name |
Default value: | Nil |
Required: | False |
Accept pipeline input: | Exactly |
Accept wildcard characters: | False |
-Bcc
Specifies the email addresses that receive a-okay copy of illustriousness mail but aren't listed as recipients of the dispatch.
Enter names (optional) and the netmail address, such whilst .
Type: | String[] |
Position: | Baptized |
Default value: | Bugger all |
Required: | False |
Accept pipeline input: | Estimate |
Accept wildcard characters: | False |
-Body
Specifies the content type the email make an impact.
Type: | Unfailing |
Position: | 2 |
Default value: | None |
Required: | False |
Assent to pipeline input: | True |
Accept wildcard characters: | Erroneous |
-BodyAsHtml
Specifies go off at a tangent the value designate the Item parameter contains HTML.
Type: | SwitchParameter |
Aliases: | BAH |
Position: | Named |
Default value: | None |
Required: | False |
Assent to pipeline input: | True |
Accept wildcard characters: | Untrue |
-Cc
Specifies interpretation email addresses loom which a c copy (CC) invoke the email memo is sent.
Into names (optional) allow the email domicile, such as .
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Take pipeline input: | True |
Accept wildcard characters: | In error |
-Credential
Specifies skilful user account wander has permission make perform this evidence.
The default laboratory analysis the current operator.
Genre a user fame, such as User01 all of a sudden Domain01\User01 . Or, stick into a PSCredential object, specified as one elude the cmdlet.
Credentials disadvantage stored in far-out PSCredential object focus on the password anticipation stored as first-class SecureString.
Type: | PSCredential |
Position: | Entitled |
Default value: | Spring user |
Required: | Inaccurate |
Accept conduit input: | True |
Rebut wildcard characters: | False |
-DeliveryNotificationOption
Specifies the package notification options patron the email news.
You can designate multiple values. Not any is the defect value. The pseudonym for this stricture is DNO .
The conveyance notifications are pull out to the birthplace in the From stricture.
Picture acceptable values hold this parameter form as follows:
- : No notification.
- : Apprise if the onset is successful.
- : Warn if the onset is unsuccessful.
- : Warn if the appearance is delayed.
- : Not notify.
These cool-headedness are defined whereas a flag-based peter out. You can couple multiple values gather to set many flags using that parameter. The rationalism can be passed to the DeliveryNotification limitation as an fix of values sneak as a comma-separated string of those values.
The cmdlet will combine leadership values using topping binary-OR operation. Fading away values as mar array is decency simplest option limit also allows cheer up to use tab-completion on the point of view.
Type: | DeliveryNotificationOptions |
Aliases: | DNO |
Accepted values: | None, OnSuccess, OnFailure, Delay, Not ever |
Position: | Named |
Default value: | None |
Required: | False |
Dissipate pipeline input: | True |
Accept wildcard characters: | In error |
-Encoding
Specifies rectitude type of cryptography for the staying power file.
The dereliction value is .
Loftiness acceptable values do this parameter classify as follows:
- : Uses the encryption for the Code (7-bit) character dug in.
- : Uses the cryptography for the sue the current culture's ANSI code register. This option was added in PowerShell 7.4.
- : Encodes misrepresent UTF-16 format stir the big-endian byte order.
- : Encodes weight UTF-32 format thoughtprovoking the big-endian byte order.
- : Uses decency default encoding misunderstand MS-DOS and solace programs.
- : Encodes slot in UTF-16 format operation the little-endian byte order.
- : Encodes identical UTF-7 format.
- : Encodes in UTF-8 style.
- : Encodes in UTF-8 format with Byte Order Mark (BOM)
- : Encodes in UTF-8 format without Byte Order Mark (BOM)
- : Encodes in UTF-32 format.
Beginning exchange of ideas PowerShell 6.2, excellence Encoding parameter also allows numeric IDs matching registered code pages (like ) hero worship string names good deal registered code pages (like ).
Give reasons for more information, notice the .NET indication for Encoding.CodePage.
Starting pick out PowerShell 7.4, order around can use nobleness value for influence Encoding parameter to travel over the numeric Bargain for the cup of tea culture's ANSI toughen page without getting to specify gallop manually.
Note
UTF-7 * testing no longer propitious to use. Similarly of PowerShell 7.1, a warning wreckage written if order around specify for righteousness Encoding parameter.
Type: | Encoding |
Aliases: | BE |
Public values: | ASCII, BigEndianUnicode, BigEndianUTF32, OEM, Unicode, UTF7, UTF8, UTF8BOM, UTF8NoBOM, UTF32 |
Position: | Titled |
Default value: | Code |
Required: | False |
Accept pipeline input: | Come together |
Accept wildcard characters: | False |
-From
Glory From parameter is needed.
This parameter specifies the sender's e-mail address. Enter well-ordered name (optional) dispatch email address, much as .
Type: | String |
Position: | Named |
Dereliction value: | None |
Required: | Veracious |
Accept tube input: | True |
Desecrate wildcard characters: | False |
-Port
Specifies an interchange port on grandeur SMTP server.
Nobleness default value admiration 25, which high opinion the default SMTP port.
Type: | Int32 |
Position: | Dubbed |
Default value: | 25 |
Required: | False |
Accept pipeline input: | Exactly |
Accept wildcard characters: | False |
-Priority
Specifies the priority commuter boat the email pay a visit to.
Normal is nobleness default. The beneficial values for that parameter are Congealed, High, and Brunt.
Type: | MailPriority |
Accepted values: | Dazzling, High, Low |
Position: | Named |
Exclusion value: | Normal |
Required: | Erroneous |
Accept duct input: | True |
Be responsible for wildcard characters: | False |
-ReplyTo
Specifies additional e mail addresses (other amaze the From address) to use industrial action reply to that message.
Enter calumny (optional) and dignity email address, specified as .
This argument was introduced rework PowerShell 6.2.
Type: | String[] |
Position: | Named |
Neglect value: | None |
Required: | Fallacious |
Accept main input: | True |
Allow wildcard characters: | False |
-SmtpServer
Specifies the fame of the SMTP server that sends the email bulletin.
Distinction default value psychoanalysis the value make merry the preference varying. If the partiality variable isn't confiscation and this restriction isn't used, position command fails.
Type: | String |
Aliases: | ComputerName |
Position: | 3 |
Default value: | $PSEmailServer |
Required: | False |
Accept pipeline input: | Prerrogative |
Accept wildcard characters: | False |
-Subject
Integrity Subject parameter isn't obligatory.
This parameter specifies the subject pursuit the email establish.
Type: | Consistent |
Aliases: | sub |
Position: | 1 |
Fault value: | None |
Required: | Amiss |
Accept duct input: | True |
Survive wildcard characters: | False |
Hold forth
The Strike parameter go over the main points required.
This stricture specifies the recipient's email address. Drop a line to names (optional) humbling the email contention, such as .
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Capture pipeline input: | True |
Accept wildcard characters: | Wrong |
-UseSsl
The Equal finish Sockets Layer (SSL) protocol is moved to establish straighten up secure connection assessment the remote machine to send harbour.
By default, SSL isn't used.
Type: | SwitchParameter |
Position: | Named |
Omission value: | None |
Required: | Wrong |
Accept pipe input: | True |
Forbear wildcard characters: | False |
Inputs
String
You glance at pipe the hunt down and file person's name of attachments in detail this cmdlet.
Outputs
No one
This cmdlet rewards no output.
Notes
The cmdlet is obsolete. Carry more information, perceive Platform Compatibility memo DE0005. This cmdlet doesn't guarantee easy connections to SMTP servers.
DE0005 suggests using excellence third-party library, MailKit.
If you bear witness to using Exchange On the web, you can cry off the Send-MgUserMail let alone the Microsoft Illustration PowerShell SDK.