从Azure功能将Azure Blob附加到PowerShell中的电子邮件
我在PowerShell中编写了一个Azure函数,其输入和输出绑定与存储输入和输出csv文件的Blob存储相同。我可以通过功能发送带有blob附件的电子邮件,但电子邮件的附件类型为file,而不是csv。所以我必须下载并手动添加.csv扩展名。如何发送附件中带有扩展名的输出csv文件?我的电子邮件代码如下:从Azure功能将Azure Blob附加到PowerShell中的电子邮件,powershell,azure,azure-functions,azure-blob-storage,sendgrid-api-v3,Powershell,Azure,Azure Functions,Azure Blob Storage,Sendgrid Api V3,我在PowerShell中编写了一个Azure函数,其输入和输出绑定与存储输入和输出csv文件的Blob存储相同。我可以通过功能发送带有blob附件的电子邮件,但电子邮件的附件类型为file,而不是csv。所以我必须下载并手动添加.csv扩展名。如何发送附件中带有扩展名的输出csv文件?我的电子邮件代码如下: # Send Email using SendGrid with file attachment $username ="Username" $password = ConvertTo-S
# Send Email using SendGrid with file attachment
$username ="Username"
$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username,
$password
$SMTPServer = "smtp.sendgrid.net"
$emailFrom = "No-reply@azureadmin.com"
[string[]]$emailTo = "some-email"
$subject = "Sending sample email using SendGrid Azure and PowerShell"
$body = "This is sample email sent using Sendgrid account create on Microsoft
Azure. The script written is easy to use."
$attachment = $outputBlob
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -
Port 587 -From $emailFrom -To $emailTo -Subject $subject -Body $body -
BodyAsHtml -Attachments $attachment
我用相同的代码创建了输出文件,但我不确定如何将其附加到电子邮件
outputBlob是一个名为outputfile.csv的csv文件,它与inputfile存储在同一容器中。我正在用同样的脚本创建这个输出文件。因此,我的容器名是“mycsvcontainer”,Azure函数绑定中我的blob的路径是“mycsvcontainer/outptfile.csv”。blob的名称是outputBlob,我在上面的脚本中使用它。inputBlob的名称类似。outputblob的类型是什么?因为
-Attachments
需要路径+文件名。outputBlob是一个名为outputfile.csv的csv文件,它存储在与inputfile相同的容器中。我正在用同样的脚本创建这个输出文件。因此,我的容器名是“mycsvcontainer”,Azure函数绑定中我的blob的路径是“mycsvcontainer/outptfile.csv”。blob的名称是outputBlob,我在上面的脚本中使用它。inputBlob的名称与之类似。@Thomas-你知道怎么做吗?
$StorageAccountName = 'mystorageaccount'
$StorageAccountKey = "storageaccountkey"
$StorageContext = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey
$FileName = 'filename'
$ContainerName = 'mycontainer'
#Get attachment from blob storage
$a = Get-AzureStorageBlobContent -Container $ContainerName -Blob $FileName -Context $StorageContext
$attachment = $a.Name
$MyCredential = "SendEMail"
$EmailBody = "Test"
$Body = $EmailBody.replace("|","`n`r")
$subject = "Tets"
$userid= "Test@test.com"
$emailTo = "emailid@emaildomain.com"
#Get the PowerShell credential
$Cred = Get-AutomationPSCredential -Name $MyCredential
Send-MailMessage `
-To $emailTo `
-Subject $subject `
-Body $Body `
-UseSsl `
-Port 587 `
-SmtpServer 'smtp.sendgrid.net' `
-Attachments $attachment `
-From $userid `
-Credential $Cred `