smtpConnectionTest

Opens a connection to an SMTP server to verify reachability and (optionally) credentials, the same way cfmail does. Uses the same TLS ladder as cfmail: implicit TLS (useSsl), else STARTTLS (useTls, the default), else plaintext; a requested-but-unavailable TLS is a failure, never a silent downgrade. Returns a struct with success (boolean), authFailed (true when the server rejected the credentials, SMTP 534/535/538) and message (a human-readable detail, empty on success).

smtpConnectionTest(host [, port] [, username] [, password] [, useTls] [, useSsl] [, timeout]) → returns struct

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

host string
Required

The SMTP server host.

port numeric
Default: 25

The SMTP port (default 25).

username string

Optional SMTP username; when present the password is used and auth is tested.

password string

Optional SMTP password.

useTls boolean
Default: true

Use STARTTLS when available (default true).
Values:
  • true
  • false

useSsl boolean
Default: false

Use implicit TLS (default false); takes precedence over useTls.
Values:
  • true
  • false

timeout numeric
Default: 10

Connection timeout in seconds (default 10).

Examples
Sample code invoking the smtpConnectionTest function

Check that an SMTP relay is reachable on port 587.

result = smtpConnectionTest("smtp.example.com", 587);
writeDump(result.success);

A wrong password reports authFailed = true.

result = smtpConnectionTest("smtp.example.com", 587, "user", "wrong", true);
writeDump(result.authFailed);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub