VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

send-mailmessage use in powercli scripts

Hi Luc,

Have you used send-mailmessage in powercli .this is not entirely powercli question but it can be utilized in powercli scripts  .

i am trying to find what all needs to be configured to  use this when two users are in different domain .

like from user1@xyz.com     to user2@abc.com

appreciate if yu can suggest yur thought on the above.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is not a lot you can do in your script I'm afraid. All the security and restrictions concerning mail sending is done on the mail server.


To send an email you need to define the server (SmtpServer param) over which the mail is sent.

You (the account under which you invoke the Send-MailMessage cmdlet) will need to be authorised to connect to the mail server.

The station also needs to be allowed to send email via that mail server. The list of allowed servers to send mail might be restricted to avoid spamming.


If the mail can reach the to To address, depends if the mail server can find the route to the destination user's mail server/mailbox.

In PowerShell you just send it like this. After that it is the mail setup in your environment.

$sMail = @{

  SmtpServer = 'mail.domain.com'

  From = 'user1@xyz.com'

  To = 'user2@abc.com'

  Subject = 'Test' 

}

Send-MailMessage @sMail


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

There is not a lot you can do in your script I'm afraid. All the security and restrictions concerning mail sending is done on the mail server.


To send an email you need to define the server (SmtpServer param) over which the mail is sent.

You (the account under which you invoke the Send-MailMessage cmdlet) will need to be authorised to connect to the mail server.

The station also needs to be allowed to send email via that mail server. The list of allowed servers to send mail might be restricted to avoid spamming.


If the mail can reach the to To address, depends if the mail server can find the route to the destination user's mail server/mailbox.

In PowerShell you just send it like this. After that it is the mail setup in your environment.

$sMail = @{

  SmtpServer = 'mail.domain.com'

  From = 'user1@xyz.com'

  To = 'user2@abc.com'

  Subject = 'Test' 

}

Send-MailMessage @sMail


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i am checking if some modification on mail server and process you described can be achieved for the sake of not getting false alerts .

but if proper modification on mail server is done this command can be quite useful .

do you see any alternative of this which can be utilized in powercli scripts.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Before the introduction of the Send-MailMessage cmdlet, people tended to use the Net.Mail.SmtpClient class to send emails from a PS script.

But this method also depends on what the mail server allows and knows.

There are alternatives for sending message, Slack is for example another option, and you could do this from within a PS script with the PSSlack module.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks Luc iam checking this.

0 Kudos