how-to, how to, microsoft

Powershell is a powerful Integrated Scripting Environment (ISE) that can be used to write and debug scripts. This scripting environment can perform a wide range of functions, including sending emails using scripts and cmdlets. This can help the system administrators in automating the process of sending bulk emails.

To use PowerShell to send emails, users must specify the parameters, including the SMTP server that they want to use for pushing the mail. All these whereabouts are discussed in today’s article.

Parameters You Can Use To Send Email From PowerShell

These are some major parameters you can use to send Emails using PowerShell.

  • -From : Email address of the sender
  • -To : Email Address of the mail Receiver
  • -Cc: Email address of the recipient who gets the Email message’s Carbon Copy
  • -Attachments : File path of the attachment that is to be sent with the Email
  • -Subject : Email’s subject
  • -Body: Body (Main message) of the Email
  • -Credentials : SMTP server login credentials. This is used to authenticate the SMTP server
  • -SmtpServer : Address of the SMTP server ( For instance: smtp.gmail.com)
  • -Port : Port on the SMTP server
  • -Use Ssl: Use Secure Sockets Layer Protocol.

Send Emails From Powershell

The most common method to send e-mails using PowerShell is by using the Send-MailMessage cmdlet. There are other popular tools like system.netmail API, EASendMAil component, and Microsoft Graph API. 

The Send-MailMessagecmdlet, even after being labeled obsolete by Microsoft, still is the most convenient option for sending emails from PowerShell.

  • If the E-mail is to be sent to multiple users,Send-MailMessage -From "yosar72796@covbase.com" -To "tnt@tnt.com", "hr@tnt.com" -Credentials (Get-Credential) -SmtpServer "smtp.outlook.com"
    how-to, how to, microsoft
  • If you want to send the email with an attachment, you can add -Attachmentparameter.
    Send-MailMessage -From "Nishant@tnt.com" -To "tnt@tnt.com", "hr@tnt.com" -Attachment "C:tempSome random file.txt" -Credentials (Get-Credential) -SmtpServer "smtp.outlook.com"
    how-to, how to, microsoft
  • To add CC, use the parameter -CC “E-mail receiving the copy of the mail” in thecmdlet.

Note: You can even use the value $PSEmailServer, as the SMTP setting instead of the Smtp-Server. This is the default SMTP configuration on Powershell.

Send Email from PowerShell with Gmail SMTP

Before May 2022, in order to use Gmail SMTP to send email from PowerShell, users had to first Enable the less secure apps from Google’s security control panel.

After this feature was removed by Google, to use the Google SMPT server, users have to disable the two-factor authentication on their Gmail account, create app passwords, and then use those credentials in the PowerShell code.

Once You have set up the app password, you can use the cmdlets to send the E-mail. To use the Gmail SMPT, you must also have SSL enabled. All the required parameters to use the Gmail SMTP for sending an E-mail are used in this script:

$EmailFrom = "Nishant@gmail.com" $EmailTo = "tnt@tnt.com" $Subject = "Email Subject" $Body = "Main Message." $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body) 

how-to, how to, microsoft

Here is the list of SMTP servers you can use, along with their address and Ports.

NameSMTP Server AddressPortGmail smtp.gmail.com587Outlook.comsmtp.mail.outlook.com587Yahoosmtp.mail.yahoo.com587AOLsmtp.mail.me.com587AOLsmtp.aol.com465

TECH NEWS RELATED

AYA NEO Pocket Air is an Android gaming handheld with OLED display

Android is now fully ready to be utilized in a gaming handheld console. We have already seen a couple of new Android handhelds from big companies last year. And now more companies are launching their handhelds. The one we are talking about today is the AYA NEO Pocket Air. This ...

View more: AYA NEO Pocket Air is an Android gaming handheld with OLED display

Jaguars vs Chiefs live stream: how to watch the NFL playoff game online

(Image: © Getty Images / David Eulitt) Swipe to scroll horizontally Jaguars vs Chiefs live stream Kick-off: Saturday, January 21, 4.30pm ET / 1.30pm PT / 9.30pm GMT TV channel: NBC Live stream: Peacock TV (US) | DAZN (CA) | Sky (UK) | 7Plus (AU) Use ExpressVPN to watch ...

View more: Jaguars vs Chiefs live stream: how to watch the NFL playoff game online

Word can’t do this because a dialog box is open

Microsoft Word is the best word editor available for users. While it is almost perfect, many users report a problem with the application where they encounter the error Word can’t do this because a dialog box is open. The error occurs while creating a new Word document or opening an ...

View more: Word can’t do this because a dialog box is open

A Twisted New Body Dysmorphia Romantic Film Looks Gruesomely Unique

Some movie trailers do their best to push all the information you might need before the premiere to let you properly gauge your interest. Other trailers don’t care about all that and only want to show you a series of odd sequences you cannot piece together, but know you’ll ...

View more: A Twisted New Body Dysmorphia Romantic Film Looks Gruesomely Unique

How to Disable Screenshot Thumbnail Previews on Mac

Modern versions of macOS feature a floating thumbnail preview for screenshots that allows users to quickly apply edits to their screenshots before they save them. If you find this interface too obtrusive, or simply prefer to edit your screenshots later using the Preview app, Here is how you can ...

View more: How to Disable Screenshot Thumbnail Previews on Mac

LG’s smart projector is the square cousin of Samsung’s cool The Freestyle

This Tiny MSI PC is Packed With Power

MSI Following the example set by the Mac Mini, many Windows-powered compact PCs have popped up recently with solid hardware. If none have quite caught your eye, though, maybe this PC by MSI will. MSI has just released a new tiny PC called the Cubi 5 12M, and it’s ...

View more: This Tiny MSI PC is Packed With Power

Logitech’s New Colorful Keyboards and Mice Look Great

Logitech Logitech makes some of the best keyboards and best mice around, and you might be familiar with the company’s RGB-packed gaming products. These new peripherals are really packed with color, but we’re not really talking about lights. Logitech has announced a range of new colors for a bunch ...

View more: Logitech’s New Colorful Keyboards and Mice Look Great

10 Best Solutions To Fix DNS Errors In Windows

[7 Fixes] Windows Photos App Slow To Open Issue In Windows

“Part of the Journey Is the End;” Marvel’s Avengers Seems to be Shutting Down

How To Find Your Laptop IP Address

8 Fixes: Microsoft Windows Security Not Opening

9 Best Ways To Retrieve A Downloaded Movie On Your Laptop

How To Snip Screen On Your Laptop?

How To Connect AirPods To A Laptop?

Satechi Thunderbolt 4 Slim Hub review: A sleek and portable laptop hub

Wi-Fi routers are being hit by a dangerous new Android malware with extra DNS hacks

7 Best Ways To Fix DistributedCOM Error In Windows

12 Easy Fixes For Webcam Not Working In Windows

OTHER TECH NEWS

Top Car News Car News