Attaching an Azure Blob to an email

Welcome Forums General PowerShell Q&A Attaching an Azure Blob to an email

Viewing 1 reply thread
  • Author
    Posts
    • #187921
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      I have been ripping my hair out trying to get a CSV file that I am writing to a container to attach to an email I am sending.  The file is being written to the container.  I can see it.   But the smtp.Attachments.Add() causes an error: "You cannot call a method on a null-valued expression."    This is the relevant code.  What am I missing here?

       

      $att = New-Item filename.csv -ItemType file
      $DataSet.Tables[0] | Export-CSV -NoTypeInformation $att

      Set-AzureStorageBlobContent -File $att -Container $DestContainer -Context $StorageContext -Force
      $blob = Get-AzureStorageBlob -Container $DestContainer -Context $StorageContext
      $attachment = $blob.Name

      $smtp.Attachments.Add($attachment)
      $smtp.Send($From, $To, $subject, $body)

       

    • #187933
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      I've tried it this way as well...

       

       $blob = Get-AzureStorageBlobContent -Container $DestContainer -Blob $att -Context $StorageContext
       $attachment = $blob.Name
      But this produces the following error:
      Can not find blob 'C:\Temp\n3pwth0j.msw\filename.csv' in container 'ContainerName', or the blob type is unsupported.
      It has to be one of these cmdlets right?
Viewing 1 reply thread
  • You must be logged in to reply to this topic.