I’m working with a Zapier automation that includes a Python code step. The script generates multiple URLs as output, but when I try to use this data in a Gmail step, everything gets displayed on a single line instead of being properly formatted.
Currently my Python step returns something like this:
def process_urls():
file_links = [
"https://mycompany.sharepoint.com/file1abc123def456",
"https://mycompany.sharepoint.com/file2ghi789jkl012",
"https://mycompany.sharepoint.com/file3mno345pqr678"
]
return {'output': file_links}
When I use this output in my Gmail step, all the URLs appear smooshed together in one line. I need them to show up as separate lines in the email body like this:
https://mycompany.sharepoint.com/file1abc123def456
https://mycompany.sharepoint.com/file2ghi789jkl012
https://mycompany.sharepoint.com/file3mno345pqr678
Is there a way to modify my Python code or use a Zapier formatter to achieve proper line breaks? Any suggestions would be helpful.
Had this exact problem a few months back - the fix is pretty simple. Zapier doesn’t handle line breaks when passing arrays between steps, so you need to join your URLs with newline characters in your Python code before returning them. Just change your return statement to: return {'output': '\n'.join(file_links)}. This turns your array into a single string with line breaks built in. Gmail will see those newline characters and put each URL on its own line. I’ve used this fix in several workflows now and it works every time across different email providers.
try \n\n instead of just \n for double line breaks - gmail sometimes needs that extra spacing to render correctly. also make sure your gmail step is set to html format, not plain text, or it’ll ignore the formatting.
Here’s what worked for me: use HTML line breaks in your Python output instead of newlines. Change your return to return {'output': '<br>'.join(file_links)}. This formats properly whether Gmail reads it as HTML or plain text. I’ve found <br> tags way more reliable than \n since some email clients strip newlines but keep HTML breaks. For best results, combine both: return {'output': '<br>\n'.join(file_links)}. You’ll get HTML breaks AND newlines, so it works across different email providers and viewing modes.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.