[TUTO] – Powershell : send a mail in powershell

0
2
1 Star2 Stars3 Stars4 Stars5 Stars (Aucun Vote)
Loading...

Today I would like to share a function that I use a lot and which is quite simple, but very useful, it’s the “Send-MailMessage”.

In fact as the title suggests the goal is to send a mail in powershell, I use including this function in my script to warn one or a group of persons for the purpose of a script, by example to confirm the creation of a user sent to the admins group or to send logs in case of success or failure of a script.

 

How to send a mail in powershell?

Before you can send a mail it must have some information, the first is your SMTP server, it is a server that will forward your mail via SMTP (Simple Mail Transfer Protocol) Protocol. Then you must have an e-mail address that can send a message allowed by your e-mail server. And finally know your recipient (you guessed). Once all these collected information see how to use them.

The command we will use is “Send-MailMessage” to which we will add the following arguments:

-“From” corresponding with the mailing address of the mail

-“To” corresponding to the recipient of the mail

-“Subject” corresponding about the mail

-“Body” corresponding to the body of the mail

-“SmtpServer” corresponding to your server SMTP related

– “Attachments” has an attachment

 

Which can give the following command:

 

So now you know how to send a mail in powershell and I advise you to use it without moderation.

Jérémy Lebon
Fondateur de sys-Advisor.com, Ingénieur de production Informatique dans l'e-commerce mais passionné avant tout, je partage mon quotidien à travers ce site. #sysadmin #microsoft #vmware #tech #geek @sysadvisor Contact Skype Enterprise : jeremy.lebon@sys-advisor.com

LAISSER UN COMMENTAIRE

Please enter your comment!
Please enter your name here