Your overall approach is on the right track! Here is a production-safe flow design with a few important corrections to make it reliable.
CORRECT FLOW STRUCTURE:
1. Trigger: Recurrence (daily or on demand)
2. Get emails from subfolder
Action: Get emails (V3) — Office 365 Outlook
Set Folder to your DSN subfolder, Has Attachments = Yes
3. Apply to each email (loop emails)
4. Get attachments (inside email loop)
Action: Get attachments (V2) — returns a list of attachments for that email
5. Apply to each attachment (nested loop on attachments)
6. Check if attachment is .eml
Condition using:
endsWith(items('Apply_to_each_Attachment')?['Name'], '.eml')
NOTE: Reference the attachment loop name, not the email loop name.
7. Get attachment content
Action: Get attachment (V2)
This requires BOTH the Message ID AND the Attachment ID — not just the email ID.
- Message ID: from the email loop item
- Attachment ID: from the attachment loop item
8. Decode the attachment body
Use a Compose action with:
base64ToString(body('Get_attachment_(V2)')?['ContentBytes'])
9. Split into lines — USE CRLF, not just LF
.eml files commonly use CRLF line endings (\r\n), so use:
split(outputs('Compose_decoded'), decodeUriComponent('%0D%0A'))
Using only %0A (LF) will work sometimes but fail on many real DSN emails.
10. Extract email address and error using MARKERS, not fixed line positions
Fixed line numbers like [0] and [2] are unreliable because DSN format
varies between Exchange, Gmail, Postfix, SendGrid, and SES servers.
Use marker-based extraction instead:
For the recipient email address:
trim(first(split(last(split(outputs('Compose_decoded'), 'Final-Recipient:')), decodeUriComponent('%0D%0A'))))
For the error/diagnostic message:
trim(first(split(last(split(outputs('Compose_decoded'), 'Diagnostic-Code:')), decodeUriComponent('%0D%0A'))))
For the status code (optional but useful):
trim(first(split(last(split(outputs('Compose_decoded'), 'Status:')), decodeUriComponent('%0D%0A'))))
11. Add a row to Excel
Action: Add a row into a table (Excel Online - OneDrive)
Map extracted values to your columns.
12. Archive the email
Action: Move email (V2) — move from DSN subfolder to Archive subfolder
QUICK SUMMARY OF WHAT TO WATCH OUT FOR:
- Always use a nested attachment loop — Get Attachment (V2) needs both
Message ID and Attachment ID, not just the email ID.
- Use %0D%0A (CRLF) for splitting .eml lines, not just %0A (LF).
- Never rely on fixed line positions [0], [2] etc. — DSN formats differ
by mail server. Use marker strings like Final-Recipient: and
Diagnostic-Code: for reliable extraction.
- The endsWith() check must reference the attachment loop variable,
not the outer email loop variable.