Giter VIP home page Giter VIP logo

azureautomation / sending-email-from-azure-automation-using-office-365--secure-smtp- Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 108 KB

This script  demonstrates how to send an email from Microsoft Azure automation using secure SMTP for sending the mail. In this setup the script is sending mails using Microsoft Office 365. This is could a nice feature to have to inform someone that Azure Automation just perform

License: Other

PowerShell 100.00%
azureautomationrunbookgallery

sending-email-from-azure-automation-using-office-365--secure-smtp-'s Introduction

Sending email from Azure Automation using Office 365 (Secure SMTP)

This script  demonstrates how to send an email from Microsoft Azure automation using secure SMTP for sending the mail. In this setup the script is sending mails using Microsoft Office 365. This is could a nice feature to have to inform someone that Azure Automation just perform somekind of action and inform them about the result of that action.

You have to define Office 365 Credentials under Azure Automation Assets. You should also change the references within the script to point to the correct Asset name.

Hope you enjoy sending some automated mails from Azure

 

Image

 

 

PowerShell Workflow Edit|Remove powershellworkflow workflow SendMailUsingOffice365 {

 $MyCredential = 'enSence Office 365'
 $Body = 'Content of mail'
 $subject = 'Mail send from Azure Automation using Office 365'
 $userid='[email protected]'
 
# Get the PowerShell credential and prints its properties
$Cred = Get-AutomationPSCredential -Name $MyCredential
if ($Cred -eq $null)
{
    Write-Output 'Credential entered: $MyCredential does not exist in the automation service. Please create one `n'   
}
else
{
    $CredUsername = $Cred.UserName
    $CredPassword = $Cred.GetNetworkCredential().Password
    
    Write-Output '-------------------------------------------------------------------------'
    Write-Output 'Credential Properties: '
    Write-Output 'Username: $CredUsername'
    Write-Output 'Password: *** `n'
    Write-Output '-------------------------------------------------------------------------'
   # Write-Output 'Password: $CredPassword `n'
}
    
 
 Send-MailMessage `
-To '[email protected]' `
-Subject $subject  `
-Body $Body `
-UseSsl `
-Port 587 `
-SmtpServer 'smtp.office365.com' `
-From $userid `
-BodyAsHtml `
-Credential $Cred

    Write-Output 'Mail is now send `n'
    Write-Output '-------------------------------------------------------------------------'

}

workflow SendMailUsingOffice365  {          $MyCredential = 'enSence Office 365'       $Body = 'Content of mail'       $subject = 'Mail send from Azure Automation using Office 365'       $userid='[email protected]'             # Get the PowerShell credential and prints its properties      $Cred = Get-AutomationPSCredential -Name $MyCredential      if ($Cred -eq $null)      {          Write-Output 'Credential entered: $MyCredential does not exist in the automation service. Please create one n'         }      else      {          $CredUsername = $Cred.UserName          $CredPassword = $Cred.GetNetworkCredential().Password                    Write-Output '-------------------------------------------------------------------------'          Write-Output 'Credential Properties: '          Write-Output 'Username: $CredUsername'          Write-Output 'Password: *** n'          Write-Output '-------------------------------------------------------------------------'         # Write-Output 'Password: $CredPassword `n'      }                      

TechNet gallery is retiring! This script was migrated from TechNet script center to GitHub by Microsoft Azure Automation product group. All the Script Center fields like Rating, RatingCount and DownloadCount have been carried over to Github as-is for the migrated scripts only. Note : The Script Center fields will not be applicable for the new repositories created in Github & hence those fields will not show up for new Github repositories.

sending-email-from-azure-automation-using-office-365--secure-smtp-'s People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.