Below is a script that can be used to send email using Powershell.
Write-Host "Sending Email"
#SMTP server name $smtpServer = "smtp.xxxx.com"
#Creating a Mail object $msg = new-object Net.Mail.MailMessage
#Creating SMTP server object $smtp = new-object Net.Mail.SmtpClient($smtpServer)
#Email structure $msg.From = "fromID@xxxx.com" $msg.ReplyTo = "firstname.lastname@example.org" $msg.To.Add("toID@xxxx.com") $msg.subject = "My Subject" $msg.body = "This is the email Body."
#Sending email $smtp.Send($msg) }
Thanks buddy . Useful Tip
Will this work without "ADD-PSSnapin" of Microsoft exchange??
OK ... now how do we get it to send text from a file, instead of a fixed string?
$msg.body = Get-Content C:\body.txt
Exception calling "Send" with "1" argument(s): "The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required"
At line:24 char:16
+ $smtp.Send <<<< ($msg)
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Or you can use the cmd-let
#$cred = get-credential
send-mailMessage -to "" -subject "test" -from "" -body "" -SmtpServer "" #-credential $cred
Hi, one question, how can i load mail body from html file?
Is there a way to get a confirmation message or mail read message from the command line?
Pretty helpfull this one, you can also find an handson example right here:
Helped me implement the mail functions into reporting scripts and such.
how i can add option authentication ?
Would someone please explain in detail how to send email using window 7 Powershell to this "email@example.com"
This script doesn't work for me... can you please help..?
how would you add multiple to addresses from a text file?
$msg.To.Add(Get-Content <path to text>
And would the text file need to be comma or semicolon separated, or have addresses on their own lines?
Do you have to have Outlook installed to send an email or will it just use the server info? I'm trying to send the email from a server. I want the scripts to run before I get in and boot up, so I set them up on the server. They will report to a file but I'd like them emailed to a group. The email doesn't go out but it works form my PC. I think it must have Outlook installed or use OWA. Am I correct?
$msg.ReplyTo Doesn't work with multiple recipient , please let me know if it is known