
Send-MailMessage -From " Bob " ` -To " Lee ", ` " Zoe " ` -Subject " Sending the Attachment from PowerShell " ` -Body " The text now can be bold or italic. It is easy! Just add a -BodyAsHtml switch, and you can start adding HTML tags in the body text. With a small change to the above script we can send rich formatted emails in the HTML format.
#Mail attachment downloader alternative password#
* PSCredential class expects us to provide a secure password or string, but what we want is to pass a plain text string, thus we need to convert it. Argument/CommandĪrray of arguments for the object constructorĬonfirms that you are using a plain text password The PowerShell’s send email credentials require a PSCredential object, which we construct using a combo of commands that at the end creates the PSCredential object instance from the namespace. ArgumentĪ little bizarre part that sets SMTP server’s username and password is explained below. Here is an official documentation of PowerShell Email. In the PowerShell world such functions are called cmdlets. " -Attachment " invoice-001.pdf " -SmtpServer -Port 587 -UseSsl -Credential ( New-Object -TypeName -ArgumentList " Your-username-goes-here ", ( ConvertTo-SecureString -String " replace-this-with-your-password " -AsPlainText -Force ) ) PowerShell Īs you noticed, we are using a PowerShell built-in function Send-MailMessage. If you want to use the command as a single line, copy/paste the following code: Send-MailMessage -From " Bob " -To " Lee ", " Zoe " -Subject " Sending the Attachment from PowerShell " -Body " The body of email goes here. This is a PowerShell way to split one long command to multiple lines. If you look at the example above, you will notice the grave accent (backtick) characters at the end of each line.
#Mail attachment downloader alternative how to#
How to use PowerShell to send email from a single-line command? If you don’t know which values to use for SMTP server and port, check this page for SMTP settings for popular email providers. Otherwise the script will not work in your environment.Īt least, change the following parameters to the values of your email: But keep in mind that you need to adjust some command line arguments and switches. Just copy/paste the script into the PowerShell window you opened in the first step. " ` -Attachment " invoice-001.pdf " ` -SmtpServer ` -Port 587 ` -UseSsl ` -Credential ( New-Object ` -TypeName ` -ArgumentList " Your-username-goes-here ", ` ( ConvertTo-SecureString ` -String " replace-this-with-your-password " ` -AsPlainText -Force ) ) How to test your script in the command line? Send-MailMessage -From " Bob " ` -To " Lee ", ` " Zoe " ` -Subject " Sending the Attachment from PowerShell " ` -Body " The body of email goes here.

An SMTP server, username and password are required for the PowerShell script to send email using an SMTP server. It uses, FROM and TO fields to set the sender and recipient, as well as the subject, body, attachment arguments to create an email message.

The following script allows you to send an email message using PowerShell. First, open the PowerShell window from the Start Menu.

We are going to use the PowerShell console to send an email message with attachments.
