Question:
I have searched through many many forums and they do explain how to do this but the technical language is just too difficult to understand as I’m very new to powershell. I would like this explained to me step by step (baby steps). I would like to run this powershell command in a batch file (.bat). I have a batch file that does robocopy backups weekly and I want the batch file to send me a email when the backup is complete. The only issue I have is the credentials, I get a pop-up box asking for the user name and password. When I eneter this information the email will send successfully. Here is what I have;
Using: powershell V2.0 Windows 7 Ultimate
1 2 |
Powershell -command send-mailmessage -to emailadress@provider.com -from emailaddress@provider.com -smtp smtp.broadband.provider.com -usessl -subject 'backup complete' |
Answer:
1 2 3 4 5 6 7 8 9 |
$from = "example@mail.com" $to = "example@mail.com" $smtp = "smtpAddress.com" $sub = "hi" $body = "test mail" $secpasswd = ConvertTo-SecureString "yourpassword" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential($from, $secpasswd) Send-MailMessage -To $to -From $from -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml |