I have an Azure Function written in PowerShell with input and output binding as same Blob storage which stores input and output csv files. I was able to send an email from the function with the blob attachment but the email has the attached file of Type File instead of csv. So I have to download and manually add .csv extension to it. How can I send my output csv file with the extension in the attachment? I have my email code as below:
# 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 = "[email protected]"
[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
I have the output file created in the same code, but I'm not sure how to attach it to email.
The outputBlob is a csv file called outputfile.csv which is stored in the same container as the inputfile. I am creating this output file in this same script. So my container name is say "mycsvcontainer" and the path for my blob in the Azure Function binding is "mycsvcontainer/outptfile.csv" the name of the blob is outputBlob which i use in my script above. Similar are the names for inputBlob.
-Attachments
expects the path + filename. - Thomas