Send SMTP email from powershell script (SMTP Auth)


************************************* being script ***************

#OFFICE 365 working

$email_username="username@xyz.com"

$email_password = ConvertTo-SecureString -string "password" -AsPlainText -Force;

$email_smtp_host = "smtp.office365.com";

$email_smtp_port = 25;

$email_smtp_SSL = 1;

$email_from_address = "username@xyz.com";

$email_to_addressArray = @("himanshu@test.in");

$credential=New-Object System.Management.Automation.PSCredential($email_username,$email_password);

 

cls

 

Send-MailMessage -From "$email_from_address" -To $email_to_addressArray -Subject "Test email from powershell" -Body "This is only a test" -SmtpServer $email_smtp_host -Credential $credential -UseSsl -Port $email_smtp_port



********************************** END ************************

No comments: