Send email via PowerShell with authentication on the Exchange Server

If you are dealing with PowerShell commands and scripts , you may be faced with the problem of sending e-mails using PowerShell . Today in this PowerShell tutorial we would like to show you how you can send an email with authentication to the Exchange or mail server relatively easily using a small PowerShell script .

The following PowerShell code snippets are required for this.

$ secpasswd = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$ cred = New-Object System.Management.Automation.PSCredential (“USERNAME”, $ secpasswd)
Send-MailMessage -SmtpServer MAILSERVERNAME -Credential $ cred -From ‚[email protected ] ‘-To’ [email protected] ‘Subject “Test E-Mail”

Here is a brief explanation of the 3 PowerShell lines.

In the first line you pass in the command in plain text the password for the user account under which you want to send the email. It is certainly not advisable to store passwords in plain text , but in this case it is essential.

This is followed in the second PowerShell line in the ” USERNAME ” field by the name of the email account under which you want to send the email.

Send email via PowerShell with authentication

The third line contains several places. For the placeholder ” MAILSERVERNAME “, as the name suggests, you have to enter the name of your Exchange server or mail server via which you want to send the email.

This is followed by the sender email address after the ” -From ” parameter . After ” -To ” you have to enter the email address of the recipient or the recipient group. Finally, you can specify a subject line using the ” -Subject ” parameter .

If you put further text in brackets after the subject text, this text will then be transmitted in the actual email as email text.

With this short PowerShell script you can quickly and easily send emails with authentication to the mail server.

Other useful PowerShell scripts and commands can also be found in these posts here on Windows FAQ.

– Query owner of a file or folder via PowerShell
– Query all RAM information using PowerShell
– Change transparent display of the command prompt or the PowerShell console
– Software inventory using PowerShell command
– Get Hyper-V information about a VM using PowerShell
– All deactivated AD using PowerShell accounts list
– members of an AD group via PowerShell query
– number of AD (Active Directory) count objects via PowerShell
– Windows printer sharing via PowerShell command
to change startup type of Windows services via PowerShell –