Email Attachments

how to send email attachments using power automate to webapi

A couple of things.

Firstly, in your JSON body, you just need to put quotes around the value of the content property.

Body

Secondly, make sure you have a Get Attachment (V#) step prior to the HTTP action.

This step actually retrieves the contents of the attachment.

Get Attachment

Save only attachment from email in outlook

in HTML format all pictures are regarded as attachments and showed in body of the e-mail.
I've tried your code, it's working, but Attachments.Count is more then shown as attachments. In my case- 1 .xlsx file is displayed as attachments and 4 small images in body.

You can check if the attachment is embedded with function

Sub saveatt()
Dim Attachments As Outlook.Attachments
Dim AttachmentsCount As Integer
Dim Email As Outlook.MailItem
Dim FolderObj As Object
Dim FolderPath As String
Dim i As Long
Dim OutlookApp As Outlook.Application
Dim Selection As Outlook.Selection
Dim User As String

FolderPath = "C:\Users\xxx\Downloads"

Set FolderObj = CreateObject("Scripting.FileSystemObject")
If FolderObj.FolderExists(FolderPath) Then
Else: FolderObj.CreateFolder (FolderPath)
End If

Set OutlookApp = Outlook.Application
Set Selection = OutlookApp.ActiveExplorer.Selection

AttachmentsCount = 0

For Each Email In Selection

Set Attachments = Email.Attachments
For i = Attachments.Count To 1 Step -1
If IsEmbeddedAttachment(Attachments.Item(i)) = False Then
Attachments.Item(i).SaveAsFile FolderPath & "\" & Format(Email.ReceivedTime, "DD.MM.YYYY hhmm") & "_" & Attachments.Item(i).FileName
AttachmentsCount = AttachmentsCount + 1
End If
Next i

Next

If AttachmentsCount > 0 Then
MsgBox "Email Attachment(s) have been saved."
ElseIf AttachmentsCount = 0 Then
MsgBox "No Attachment were found to save."
End If

End Sub

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
xHtml = xItem.HTMLBody
xID = "cid:" & xCid
If InStr(xHtml, xID) > 0 Then
IsEmbeddedAttachment = True
End If
End If
End Function

This way works

Add text to email body after removing attachments

Sub DelAtt()
Dim objSelection As Outlook.Selection
Dim i, n As Long
Dim objMail As Outlook.MailItem
Dim objAttachment As Outlook.Attachment
Dim strFileType As String

Dim del_att_list As String

'Get the selected emails
Set objSelection = Outlook.Application.ActiveExplorer.Selection

'Process each email one by one
For i = objSelection.Count To 1 Step -1
If TypeOf objSelection(i) Is MailItem Then
Set objMail = objSelection(i)
If objMail.Attachments.Count > 0 Then
For n = objMail.Attachments.Count To 1 Step -1
Set objAttachment = objMail.Attachments.Item(n)
'Get the attachment file type
strFileType = Right(objAttachment.FileName, Len(objAttachment.FileName) - InStrRev(objAttachment.FileName, ".")) ' InStrRev instead of InStr to find exactly the last dot
'Leave 'obr' attachments, Delete all other types of attachments
Select Case strFileType
Case Is <> "obr"
del_att_list = del_att_list & Replace("<<Attachment deleted: #>>", "#", objAttachment.FileName) & vbLf ' add filename to list of deleted attachments
objAttachment.Delete
Case Else
End Select
Next
If del_att_list <> "" Then 'smth was deleted
With objMail
.Body = del_att_list & vbLf & .Body ' add lines to the body top
.Save
End With
End If
End If
End If
Next i
End Sub

Before Sample Image



After Sample Image



Related Topics



Leave a reply



Submit