---
title: Send email with body
summary: Sends a subject-and-body message through the legacy SOAP mail service, switching between HTML and plain-text transmission according to the caller's format flag.
status: draft
owner: SAIF Documentation Generator
last_reviewed: 2026-07-30
library: SAIF.Framework.Mail
reference_type: package
operation_id: MAIL-OP-002
trigger: Caller invokes `Mail.SendMail(inToAddress, inFromAddress, inSubject, inMessage, [isHtml])`.
---

# Send email with body

This is the library's general-purpose send operation: it delivers a subject line together with an explicit message body, in HTML or plain text, through the legacy SOAP mail service. It is the operation most application code uses when the outbound message needs actual content rather than just a subject.

| Field | Value |
| --- | --- |
| **Operation ID** | MAIL-OP-002 |
| **Trigger** | Caller invokes `Mail.SendMail(inToAddress, inFromAddress, inSubject, inMessage, [isHtml])`. |
| **Inputs** | `inToAddress`, `inFromAddress`, `inSubject`, `inMessage`, optional `isHtml`. |
| **Outputs** | SOAP dispatch to the legacy mail service; the function returns `True`. |
| **Primary components** | `Mail.SendMail`, `SAIFMail.clsSAIFMessage`, `AppGlobal.EnvironmentService` |
| **Entry point** | `SAIF.Framework.Mail\MailServices.vb` |

## Steps

1. Create a new `SAIFMail.clsSAIFMessage` SOAP client dedicated to this call.
2. Look up the mail endpoint by calling `AppGlobal.EnvironmentService.GetConfigSetting("legacyMailServiceUrl")` and assign the result to the proxy's `Url` property ([BR-001](../business-rules.md#br-001-mail-is-always-routed-through-the-configured-legacy-mail-service-url)).
   - `AppGlobal.EnvironmentService` lazily selects `WindowsEnvironmentService` or `WebEnvironmentService` depending on whether the call is running inside an HTTP request context.
   - `GetConfigSetting` refreshes configuration when it is stale, honors a developer override ahead of the loaded configuration, and returns the resolved setting value.
   - If the key is absent, the delegated lookup throws before the message is dispatched.

   > **Origin**: Steps 2.1–2.3 are implemented in [Retrieve a configuration setting](../../saif-framework-security-environmentapi/operations/retrieve-configuration-setting.md) (`SAIF.Framework.Security.EnvironmentApi`) and are executed on behalf of this operation.
3. Select the transmission format from the `isHtml` flag ([BR-002](../business-rules.md#br-002-html-body-is-the-default-format)).
   - When the caller omits `isHtml`, VB's default-parameter value supplies `True`.
   - If `isHtml` is `True`, call `SendMail(inToAddress, inFromAddress, inSubject, inMessage)`.
   - If `isHtml` is `False`, call `SendMailAsText(inToAddress, inFromAddress, inSubject, inMessage)`.
4. Dispose the SOAP proxy and clear the module-level reference.
5. Return `True` once the dispatch path completes ([BR-003](../business-rules.md#br-003-send-operations-always-report-success-regardless-of-actual-outcome)).
   - On failure: exceptions raised during endpoint resolution or the SOAP call propagate unchanged to the caller, since this function has no local error handling.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
    Start([SendMail body call]) --> Proxy[Create clsSAIFMessage]
    Proxy --> Url[Resolve legacyMailServiceUrl]
    Url --> Html{isHtml?}
    Html -->|True| HtmlSend[Call SendMail with body]
    Html -->|False| TextSend[Call SendMailAsText with body]
    HtmlSend --> Dispose[Dispose proxy]
    TextSend --> Dispose
    Dispose --> End([Return True])
```

## Failure and edge-case behavior

- `inMessage` is forwarded to the SOAP proxy exactly as supplied; the library performs no local validation, trimming, encoding adjustment, or disclaimer insertion on the body text.
- Configuration lookup failures and SOAP-layer failures both surface as unhandled exceptions, since no recovery logic exists anywhere in this call path.
- Reaching the final `Return True` statement is the only success signal this function produces; it does not reflect any acknowledgement returned by the remote mail service.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Dependencies](../dependencies.md)
- [Business rules](../business-rules.md)
- [Configuration](../configuration.md)
- [API reference](../api/index.md)

## Sources
- SAIF.Framework.Mail\MailServices.vb
- SAIF.Framework.Mail\Web References\SAIFMail\Reference.vb
- SAIF.Framework.Security\AppGlobal.vb
- SAIF.Framework.Security.EnvironmentApi\Core\Services\IEnvironmentService.cs
- SAIF.Framework.Security.EnvironmentApi\Services.Common\EnvironmentServiceBase.cs
