Thursday, December 8, 2016

PowerShell - Send Test Email (Office 365) Using PowerShell

 

Here is a sample PowerShell script which can be to test email communication using a SMTP server. In this script, I am using Office 365 SMTP server, smtp.office365.com.

 

 

 

Script:

 

#

#

$SMTPServer = "smtp.office365.com"

$EmailFrom = "Santhosh@virtualsecuritysolutions.com"

$EmailTo = "santhosh@ss-ts.com"

#

#Send-MailMessage Reference - https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/send-mailmessage

#

#

 

Write-Host "`t`tSelect 1 - SMTP Test Message with No Attachmnet" -ForegroundColor Red

Write-Host "`t`tSelect 2 - SMTP Test Message" -ForegroundColor Red

$Option = Read-Host

#

#

#

Function EmailTest_No_Attachment

{

#with no attachement

#

$Cred = Get-Credential

$Sub = "SMTP Test Message - 1 - No Attachmnet"

$Bmessage = "SMTP Test Message - 1 with Attachment"

Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $Sub -Body $Bmessage -SmtpServer $SMTPServer -Credential $cred -UseSsl -Port 587

}

 

Function EmailTest_With_Attachment

{

#with Attachment

#

$Cred = Get-Credential

$Sub = "SMTP Test Message - 1 with Attachment"

$Bmessage = "Test email body message - With Attachment"

$MyAttachment =  "C:\temp\1.docx"

Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $Sub -Body $Bmessage -Attachments $MyAttachment -SmtpServer $SMTPServer -Credential $cred -UseSsl -Port 587

}

 

#

#

 

Switch ($Option)

    {

        1 {EmailTest_No_Attachment}

        2 {EmailTest_With_Attachment}

    default {"Invalid Selection"}

    }

 

Script download options:

1.        OneDrive - https://1drv.ms/t/s!AuVEEHIwTxv9h4ZXLslcu1MzA8ZSqw

2.       TechNet Gallery - https://1drv.ms/t/s!AuVEEHIwTxv9h4ZXLslcu1MzA8ZSqw

 

 

5 comments:

You can also read more great articles on this topic at this https://writemyessay4me.org/blog/university-professors website, guys.

Hello! I just read this information and i can tell you that this article is useful. Thank you for sharing it. And look at this - https://speedypaper.com/blog/50-rhetorical-analysis-essay-topics.

I got 5 on it, let’s go half on a sack this source
.

Very useful information, especially for those who are just starting programming. Students will find a lot of interesting things. I, in turn, want to recommend a great site. Here you can find information on how to write an essay or term paper customessaymeister

This means you have to let go of your judgement about what is right and what is wrong and keep your eyes open for what can help. It could be something simple, like a kid wanting to talk to you about their day, or something huge like an invitation to a conference with like-minded people. Stay open and you are guaranteed to surpass other people who are close-minded https://essaysprofessors.com/mba-essay-writing-service.html .

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More