Encrypt Password Before Sending EMail via Hotmail/GMail

Dear All,

I can use the below script to send mail via GMail:

send-mailmessage -from someone@gmail.com -To Receiver@hotmail.com -Subject "Sending Mail with Attachment" -Body "Hello, Fun with PowerShell and EMail" -Attachments "C:\MyFolder\MyFile.txt" -Priority High -DNO OnSuccess, OnFailure -smtpServer "smtp.gmail.com" -Credential someone@gmail.com

The thing is that, this script will prompt me to enter Password for my GMail account. On the other hand, I have the option to enter password in my above script in plain-text. The problem is that whoever reads the script can know my password.

My question is --- is there anyway I can mention the password in my script in an encrypted format; so that if others are reading my script (or if I share my script) they wont be able to read plain-text password. Password should be written in the script; but not in plain-text. 

September 7th, 2015 10:15am

Do not save passwords in files.

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 11:53am

Hi Jrv -- Thanks. I understand and appreciate your point. My question is: Can I use ConvertTo-SecureString in anyway so that when I use the script it accepts my credentials securely (and transparently without prompting for password) before sending mails ?
September 9th, 2015 4:44am

Hi Jrv -- Thanks. I understand and appreciate your point. My question is: Can I use ConvertTo-SecureString in anyway so that when I use the script it accepts my credentials securely (and transparently without prompting for password) before sending mails ?

Kinda, with caveats. Here's some options:

https://social.technet.microsoft.com/Forums/en-US/8b14f492-88a2-4b25-9ae6-5278a1a8735d/hiding-password-in-the-script?forum=winserverpowershell

http://powershell.org/wp/2013/11/24/saving-passwords-and-preventing-other-processes-from-decrypting-them/

http://powershell.org/wp/2014/02/01/revisited-powershell-and-encryption/

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 8:05am

Thanks. These are good references.
September 9th, 2015 10:59am

Cheers, you're welcome.
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 11:04am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics