Skip to content

Add


Overview

The Add method creates and adds a new Account object to the Accounts object collection

Syntax

vba
Accounts.Add(SMTPAddress, AccountType, DisplayName, ApiKey, ApiURL, Encrypted, ClientId, TenantId, ClientSecret)
Parameter Name Required/Optional Type Description
SMTPAddress Required String The SMTP address for the new account
AccountType Required olAccountType The type of account.
DisplayName Optional String The display name for the new account
ApiKey Optional String The API key for the account (Mailgun specific)
ApiURL Optional String The API URL for the account (Mailgun specific)
Encrypted Optional Boolean Specifies whether the account credentials are encrypted or not
ClientId Optional String The ClientId for the account (Graph API specific)
TenantId Optional String The TenantId for the account (Graph API specific)
ClientSecret Optional String The ClientSecret for the account (Graph API specific)

Return Value

Returns a newly created Account object with the specified parameters.

Example

Example code snippet demonstrating how to add an account:

vba
Set newMailgunAccount = MailerApp.Accounts.Add SMTPAddress:="test@example.com", _
                                                ApiKey:="api-key-0123456789", _
                                                ApiUrl:="https://apiUrl.com", _
                                                AccountType:=olMailgun

Set newGraphAPIAccount = MailerApp.Accounts.Add SMTPAddress:="test@example.com", _
                                                ClientId:="11111111-1111-1111-1111-111111111111", _
                                                TenantId:="72f988bf-86f1-41af-91ab-2d7cd011db47", _
                                                ClientSecret:="HF8Q~Krjqh4r...", _
                                                AccountType:=olGraphAPI

Remarks

Each AccountType has certain parameters that although are optional syntactically, are required for that account type:

AccountType Required Parameters
olMailgun ApiKey, ApiUrl
olGraphAPI ClientId, TenantId, ClientSecret