locked
Backup notifications will not send RRS feed

  • Question

  • Hi all, 

    I am working to get backup email alerts setup for a client. I was able to get the script sending, but i had to enter my credentials each time. 

    So i went with another users' suggestion and used plain text credentials. 

    Here is the script i am using:

    $username = "PAAC@peninsulaallergyandasthma.onmicrosoft.com"

    $password = ConvertTo-SecureString "password" -AsPlainText -Force

    $psCred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)

    Import-Module MSOnline

    Connect-MSolService -Credential $psCred

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $psCred -Authentication Basic -AllowRedirection 

    Import-PSSession $Session -AllowClobber -DisableNameChecking

    $SmtpClient = new-object system.net.mail.smtpClient

    $MailMessage = New-Object system.net.mail.mailmessage

    $Smtpclient.Host = "smtp.office365.com:587 -credentials -user PAAC@peninsulaallergyandasthma.onmicrosoft.com -password password"

    $mailmessage.from = ("PAAC@peninsulaallergyandasthma.onmicrosoft.com")

    $mailmessage.To.add("nathan@northtechgroup.com")

    $mailmessage.Subject = “Backup Successful-WACP-2020”

    $mailmessage.Body = “Successful backup for Veeam Agent for Windows backup job:Daily”

    $smtpclient.Send($mailmessage)

    I feel like I'm so close! 

    My output from this script is as follows:

    "

    Exception calling "Send" with "1" argument(s): "Failure sending mail."
    At C:\Users\Nathan\Desktop\EmailBackupAlert.ps1:29 char:1
    + $smtpclient.Send($mailmessage)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SmtpException

    "

    I feel i have scoured the forums and cannot seem to get a straight answer as there are multiple scripts that claim to work. 

    No MFA enabled on this account. I have verified send/receive using owa.  I have tested port 25 as well with no luck.

    Thank you all for looking. 

    Friday, March 6, 2020 11:27 PM

All replies

  • Please edit your post and post the code correctly using the following instructions.

    How to post code in Technet Forums 

    In PowerShell 3.0 and later we use "Send-MailMessage" to send mail. 

    help send-mailmessage -online

    How to post code in Technet Forums 




    \_(ツ)_/


    • Edited by jrv Saturday, March 7, 2020 12:32 AM
    Friday, March 6, 2020 11:55 PM
  • I will edit as soon as my account is verified. It wont let me at the moment, says its spam. 

    Thank you for the tip on posting code, ill look at the send message help docs as well. 


    Saturday, March 7, 2020 12:29 AM
  • Here is the link:  How to post code in Technet Forums 

    \_(ツ)_/

    Saturday, March 7, 2020 12:32 AM
  • Here is a starter:

    $username = 'PAAC@peninsulaallergyandasthma.onmicrosoft.com'
    $password = ConvertTo-SecureString 'password' -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
    
    Import-Module MSOnline
    Connect-MSolService -Credential $psCred
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $psCred -Authentication Basic -AllowRedirection 
    Import-PSSession $Session -AllowClobber -DisableNameChecking
    
    $mailprops = @{
        From = 'PAAC@peninsulaallergyandasthma.onmicrosoft.com'
        To = 'nathan@northtechgroup.com'
        Subject = 'Backup Successful-WACP-2020'
        Body = 'Successful backup for Veeam Agent for Windows backup job:Daily'
        SmtpServer = 'smtp.office365.com'
        Port = 587
        Credential = $pscred
    }    
        
    Send-MailMessage @mailprops 
    


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Saturday, March 7, 2020 2:31 AM
    Saturday, March 7, 2020 12:35 AM