Azure 运行手册 |在事务性电子邮件中从我的 Azure 存储帐户发送附件

问题描述

我有一个 Azure Runbook 脚本,用于处理交易电子邮件、SMTP 服务器详细信息以及出于安全考虑而对发件人和收件人电子邮件进行了编辑。

出于某种原因,PowerShell 没有看到我想作为附件发送的文件,谁能看到我哪里出错了?

我附上了一张屏幕截图,以证明我拥有正确的文件(我相信它们被称为“blob”?)名称、存储帐户名称和容器名称

以下是 Runbook PowerShell 脚本,以及测试电子邮件时的错误消息。

一切顺利,

===================RUNBOOK POWERSHELL CODE===========================

$Username ="xxx"

$Password = ConvertTo-SecureString "xxx" -AsPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential $Username,$Password

$SMTPServer = "xxx"

$EmailFrom = "xxx"

[string[]]$EmailTo = "xxx"

$Subject = "xxx"

# Setting the Azure Storage Context,recommedation is to read sastoken from Runbook assets for security purpose.
$context = New-AzureStorageContext -StorageAccountName "expertadvisers" -SasToken "?sv=2019-12-12&ss=bfqt&srt=c&sp=rwdlacupx&se=2021-01-20T17:01:17Z&st=2021-01-20T09:01:17Z&spr=https&sig=PpozvhXnD6k4knwLLpyJvMF0vpnSZATabreYTzr0s2k%3D"

#Get the blob contents from storage container and store it local destination . 
Get-AzureStorageBlob -Container "notificationcontainer" -Blob "test_file.docx" -Context $context | Get-AzureStorageBlobContent -force -Destination .

#Get contents of the file
[string[]] $attachment = "test_file.docx"

$Body = "TEST MESSAGE"
    
Send-MailMessage -smtpServer $SMTPServer -Attachment $attachment -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body -Priority High -DeliveryNotificationOption OnSuccess -BodyAsHtml
Write-Output ("Email sent succesfully.")

===================ERROR MESSAGE===========================

Get-AzureStorageBlob : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error 
Message: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly 
including the signature.
At line:19 char:1
+ Get-AzureStorageBlob -Container "notificationcontainer" -Blob "test_f ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureStorageBlob],StorageException
    + FullyQualifiedErrorId : 
StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobCommand
 
Send-MailMessage : Could not find file 'C:\Temp\pyxr0xjf.rej\test_file.docx'.
At line:32 char:1
+ Send-MailMessage -smtpServer $SMTPServer -Attachment $attachment -Cre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Send-MailMessage],FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage

Azure Storage Account container screenshot

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)