---
title: "Codeunit 400 SMTP Mail"
author: "Jonas Paprotka"
url: https://jonas-paprotka.de/ref/codeunit/400-smtp-mail/
type: codeunit
id: 400
name: "SMTP Mail"
app: "Base Application"
versions: "17-19"
build: 19.5.36567.56815
obsolete: "Pending 17.0"
checked: 2026-09-20
subject: "Microsoft Dynamics 365 Business Central"
license: "Content © 2026 Jonas Paprotka. Quote freely with attribution and a link."
---

# Codeunit 400 SMTP Mail

Jonas Paprotka, https://jonas-paprotka.de/ref/codeunit/400-smtp-mail/

| | |
| --- | --- |
| App | Base Application |
| Versions | 17-19 |
| Obsolete | Pending 17.0, seen from 17. Replaced "Email Message" codeunit from "System Application". |
| Source file | SMTPMail.Codeunit.al |

## Procedures

| Name | Parameters | Returns | Access | Versions | Obsolete | Reason |
| --- | --- | --- | --- | --- | --- | --- |
| Initialize | () | - | public | 17-19 | - | - |
| AddFrom | (Text, Text) | Boolean | public | 17-19 | - | - |
| AddRecipients | (List) | - | public | 17-19 | - | - |
| AddCC | (List) | - | public | 17-19 | - | - |
| AddBCC | (List) | - | public | 17-19 | - | - |
| AddSubject | (Text) | - | public | 17-19 | - | - |
| AddBody | (Text) | - | public | 17-19 | - | - |
| AddTextBody | (Text) | - | public | 17-19 | - | - |
| AppendBody | (Text) | - | public | 17-19 | - | - |
| AppendTextBody | (Text) | - | public | 17-19 | - | - |
| GetFrom | () | Text | public | 17-19 | - | - |
| GetRecipients | (var List) | - | public | 17-19 | - | - |
| GetCC | (var List) | - | public | 17-19 | - | - |
| GetBCC | (var List) | - | public | 17-19 | - | - |
| GetSubject | () | Text | public | 17-19 | - | - |
| GetBody | () | Text | public | 17-19 | - | - |
| GetLinkedResourcesCount | () | Integer | public | 17-19 | - | - |
| IsBodyHtmlFormatted | () | Boolean | public | 17-19 | - | - |
| CreateMessage | (Text, Text, Text, Text, Text, Boolean) | Boolean | public | 17 | Pending 15.0 | This method is obsolete. A new CreateMessage overload is available, with the following parameters (FromName: Text; FromAddress: Text; Recipients: List of [Text]; Subject: Text; Body: Text). |
| CreateMessage | (Text, Text, List, Text, Text) | Boolean | public | 17-19 | - | - |
| CreateMessage | (Text, Text, List, Text, Text, Boolean) | Boolean | public | 17-19 | - | - |
| Send | () | Boolean | public | 17-19 | - | - |
| SendShowError | () | - | public | 17-19 | - | - |
| AddAttachment | (Text, Text) | Boolean | public | 17-19 | - | - |
| AddAttachmentStream | (InStream, Text) | Boolean | public | 17-19 | - | - |
| IsEnabled | () | Boolean | public | 17-19 | - | - |
| CheckValidEmailAddresses | (Text) | - | public | 17-18 | Pending 16.0 | Please call CheckValidEmailAddresses from the Mail Management codeunit directly. |
| GetLastSendMailErrorText | () | Text | public | 17-19 | - | - |
| GetSmtpErrorCodeFromResponse | (Text) | Text | public | 17-19 | - | - |
| GetFriendlyMessageFromSmtpErrorCode | (Text) | Text | public | 17-19 | - | - |
| HandleSMTPRegisterServiceConnection | (var Record Service Connection) | - | public | 17-19 | - | - |
| ShowNotificationDetail | (Notification) | - | public | 17-19 | - | - |
| GetO365SmtpServer | () | Text[250] | public | 17-19 | - | - |
| GetOutlookSmtpServer | () | Text[250] | public | 17-19 | - | - |
| GetGmailSmtpServer | () | Text[250] | public | 17-19 | - | - |
| GetYahooSmtpServer | () | Text[250] | public | 17-19 | - | - |
| GetDefaultSmtpPort | () | Integer | public | 17-19 | - | - |
| GetYahooSmtpPort | () | Integer | public | 17-19 | - | - |
| GetDefaultSmtpAuthType | () | Integer | public | 17-19 | - | - |
| OpenNotificationHyperlink | (Notification) | - | public | 17-19 | - | - |
| AddTroubleshootingLinksToNotification | (var Notification) | - | public | 17-19 | - | - |
| ApplyOffice365Smtp | (var Record SMTP Mail Setup) | - | public | 17-19 | - | - |
| ApplyOutlookSmtp | (var Record SMTP Mail Setup) | - | public | 17-19 | - | - |
| ApplyGmailSmtp | (var Record SMTP Mail Setup) | - | public | 17-19 | - | - |
| ApplyYahooSmtp | (var Record SMTP Mail Setup) | - | public | 17-19 | - | - |
| IsOffice365Setup | (var Record SMTP Mail Setup) | Boolean | public | 17-19 | - | - |
| IsOutlookSetup | (var Record SMTP Mail Setup) | Boolean | public | 17-19 | - | - |
| IsGmailSetup | (var Record SMTP Mail Setup) | Boolean | public | 17-19 | - | - |
| IsYahooSetup | (var Record SMTP Mail Setup) | Boolean | public | 17-19 | - | - |
| IsSmtpAuthErrorCode | (Text) | Boolean | public | 17-19 | - | - |
| IsSmtpRecipientErrorCode | (Text) | Boolean | public | 17-19 | - | - |
| IsSmtpSendAsErrorCode | (Text) | Boolean | public | 17-19 | - | - |
| GetOAuth2Credentials | (var Text, var Text) | - | internal | 18-19 | - | - |
| AuthenticateWithOAuth2 | () | - | internal | 18-19 | - | - |
| CheckOAuth2Authentication | () | - | internal | 18-19 | - | - |
| GetUserName | (Text, var Text) | Boolean | internal | 18-19 | - | - |

## Events

| Kind | Name | Parameters | Versions | Obsolete | Reason |
| --- | --- | --- | --- | --- | --- |
| Integration event | OnBeforeSend | (var Record SMTP Mail Setup) | 17-19 | - | - |
| Integration event | OnAfterSend | (var Text) | 17-19 | - | - |
| Integration event | OnBeforeCreateMessage | (var Text, var Text, var List, var Text, var Text) | 17-19 | - | - |
| Integration event | OnBeforeAddRecipients | (var List, var Boolean) | 17-19 | - | - |
| Integration event | OnSMTPOAuth2Authenticate | (var Text, var Text, Text) | 18-19 | - | - |

## Source

Symbols: Microsoft.BaseApplication.symbols.437dbf0e-84ff-417a-965d-ed2bb9650972, https://dynamicssmb2.pkgs.visualstudio.com/DynamicsBCPublicFeeds/_packaging/MSSymbols/nuget/v3/index.json, highest build per major on 2026-09-20.

Jonas Paprotka, 2026-09-20.
