In some cases an email as notification is all you need, maybe it is OSD related, monitor related, a script that needs to notify about a change, a friend of mine is using this to send him an email with the IP address of a server every time it starts for various reasons.
But sending mail does require a SMTP server, but if you have a live.com account or an Office 365 account you can of course use that. (Note that there are limitations on the live.com SMTP server regarding the number of emails you can send per hour)
Sending Email from PowerShell via Hotmail.com / Live.com / Outlook.com
$SmtpServer = 'smtp.live.com' $SmtpUser = 'user@outlook.com' $smtpPassword = 'P@ssw0rd' $MailtTo = 'mike@viamonstra.com' $MailFrom = 'user@outlook.com' $MailSubject = "Test using $SmtpServer" $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force) Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -SmtpServer $SmtpServer -UseSsl -Credential $Credentials
Sending Email from PowerShell via Office 365
$SmtpServer = 'smtp.office365.com' $SmtpUser = 'user@office365.com' $smtpPassword = 'P@ssw0rd' $MailtTo = 'mike@viamonstra.com' $MailFrom = 'user@office365.com' $MailSubject = "Test using $SmtpServer" $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force) Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -SmtpServer $SmtpServer -UseSsl -Credential $Credentials
/Mike
Categories: PowerShell
this doesnt work. the variables dont validate and even i get cannot connect to remote server even if I manually enter the variables. This is for office 365.
Yes, it does work, I tested it 2 seconds ago. Verify that all the settings are using real values.
you need add port $emailSmtpServerPort = ‘587’ and -port $emailSmtpServerPort