How is your experience with the OutSystems Community?
23
Views
6
Comments
Extra Spacing in Recipient Email Addresses
Question

I have encountered an issue where the total length of recipient email addresses was calculated and found not to exceed 2000 characters—specifically, it was set to 1970. 

Before sending the email, all the email address are correct as checked.

However, during the actual sending of the email, some email addresses in the "To list" exhibiting unexpected spaces, such as "test1@outsyst ems.com", make the email cannot be sent to the recipient successfully. 

What is the root cause of it? and how to solve this issue? 

Thanks a lot.

2026-05-21 04-48-12
Deepa Tiwari

Hi @Na Fu ,

  1. Generate a clean recipients string yourself

    • Build the To string as:

      "email1@domain.com,email2@domain.com,email3@domain.com"

    • Avoid inserting spaces yourself (", "); only commas.
    • Before the Send Email, log the exact string and its length with something like:

      Length(Email.To)

      so you know precisely what you are passing to the email element.
  2. Keep the total length clearly below 2000 characters

    • Do not rely on “almost 2000 is fine”. Aim for a safe margin (e.g. ≤1500–1600 characters) to account for:
      • Commas
      • Any spaces the platform may add when writing to OSSYS_EMAIL
    • If the list is long, split it into multiple emails (e.g., batches of recipients).
  3. Validate the final string before sending

    • After building the To string:
      • Replace any line breaks or tabs (\r, \n, \t) with empty string.
      • Trim to remove leading/trailing spaces.
      • Optionally, split by comma and re‑validate each email address with your own logic.
    • This avoids hidden characters that can cause addresses like test1@outsyst ems.com.
  4. Consider changing approach for mass recipients

    • Very long recipient lists (hundreds of addresses in To/CC) can be marked as spam by providers and are fragile with the platform limits.
    • Better options:
      • Use mailing lists / distribution lists.
      • Keep most recipients in BCC or send separate smaller batches.
    • This reduces both platform truncation risk and email deliverability issues. 

Hope this will help you.

Regards

Deepa

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Instead of copying official documentation as your reply, you could have provide the url to the documentation 

UserImage.jpg
Na Fu

Thank you for your reply.

But I would like to clarify that before sending, I checked the OutSystems logs, and the email addresses are all correct, with no extra spaces.

So this is what confuses me—everything is correct for sending the email, yet the sending process ends up inserting extra spaces, which impacts the functionality.

2026-05-21 04-48-12
Deepa Tiwari

Could you please share your implementation logic or a screenshot showing how you are building the list of email addresses?

UserImage.jpg
Na Fu

1. Distinct

2. Loop to validate Email address, then to set in the TempToEmail

3. Check exceeding limit or not

  • No exceeding, loop to next
  • Exceeding, add in the list, set TempToEmail as empty.
2026-08-05 13-00-31
Ramesh Gangasagare

Hi @Na Fu 

I think this is happening one layer below your OML logic — at the mail transport level, not in your app.

Per RFC 5322, long header lines (like "To") get automatically "folded" — the mail library breaks the line at a certain column width and inserts a line break + space, so the header still reads as one logical line to mail clients. This is standard behavior in most SMTP libraries, including the ones under OutSystems' hood. Normally the fold lands at a comma, so you'd never notice. But if a fold happens to land inside an address instead, you get exactly what you're seeing — a stray space like "test1@outsyst ems.com".

That's also why your pre-send validation looks clean: at that point it's still just your variable, no header has been built yet. The space appears when the platform serializes the header for actual SMTP transmission — after your logic has already handed off a correct string.

A few practical 

  1. Batch your sends — split large recipient lists into smaller groups (e.g., 20–30 per email) instead of one long To list. Shorter headers fold less, so there's less chance of a fold landing mid-address.
  2. Move most recipients to BCC, keeping To short. Also helps with deliverability on large lists.
  3. Use a mailing/distribution list on the mail server side for large recurring sends.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.