Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

SendMail.SetSMTPServer

Sets which SMTP server to use.

Component Version macOS Windows Linux Server iOS SDK
SendMail 4.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "SendMail.SetSMTPServer"; EmailID; Server { ; TLS } )   More

Parameters

Parameter Description Example Flags
EmailID The email reference number obtained using SendMail.CreateEmail function. $EmailID
Server The new SMTP Server address. "smtp.mac.com"
TLS Optional, pass 1 to use TLS, else 0.
Pass 0 for TLS and later configure CURL for STARTTLS.

Pass 1 if you use port 465 to enable TLS.
1 Optional

Result

Returns OK or error.

Description

Sets which SMTP server to use.
There are a few combinations possible.

First you can use SendMail.SetSMTPServer with SSL and pass 1 there. Then the TLS connection is right from the start.
If you pass 0, you get a plain text connection, which can be upgraded using STARTTLS if you pass 3 for CURL.SetOptionUseSSL for an upgrade of the unencrypted connection to TLS later before the credentials are sent.

Some servers don't support unencrypted, SSL or TLS, so only one may work.
And ports can be difficult, too. You can use CURL.SetOptionPort to set a port explicit or include it in the server with double colon on the end. Common ports are 25, 587 or 465.

Alternative to this method you can set CURL.SetOptionURL directly.

Examples

Start new email and setup SMTP login:

Set Variable [$EmailID; Value:MBS("SendMail.CreateEmail")]
Set Variable [$r; Value:MBS("SendMail.SetSMTPServer"; $EmailID; EMail::SMTP Server; EMail::SMTP TLS)]
Set Variable [$r; Value:MBS("SendMail.SetSMTPUserName"; $EmailID; EMail::SMTP Username)]
Set Variable [$r; Value:MBS("SendMail.SetSMTPPassword"; $EmailID; EMail::SMTP Password)]

Setup to use MobileMe server for sending:

Set Variable [ $EmailID ; Value: MBS("SendMail.CreateEmail") ]
# ... later ...
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPServer"; $EmailID; "smtp.mail.me.com") ]
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPUserName"; $EmailID; "someone@me.com") ]
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPPassword"; $EmailID; "xxxxxx") ]
# ... later ...
Set Variable [ $r ; Value: MBS("SendMail.PrepareCURL"; $EmailID; $curl) ]
# ... later ...
Set Variable [ $r ; Value: MBS("CURL.SetOptionPort"; $curl; 587) // custom port ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionUseSSL"; $curl; 3) // require encryption ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVersion"; $curl; 6) // TLS v1.2 ]

Setup to use Office 365 server for sending:

Set Variable [ $EmailID ; Value: MBS("SendMail.CreateEmail") ]
# ... later ...
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPServer"; $EmailID; "smtp.office365.com") ]
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPUserName"; $EmailID; "someone@me.com") ]
Set Variable [ $r ; Value: MBS("SendMail.SetSMTPPassword"; $EmailID; "xxxxxx") ]
# ... later ...
Set Variable [ $r ; Value: MBS("SendMail.PrepareCURL"; $EmailID; $curl) ]
# ... later ...
Set Variable [ $r ; Value: MBS("CURL.SetOptionPort"; $curl; 587) // custom port ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionUseSSL"; $curl; 3) // require encryption ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVersion"; $curl; 6) // TLS v1.2 ]
Set Variable [ $r; Value: MBS("CURL.SetOptionLoginOptions"; $curl; "AUTH=LOGIN") ]

Use alternative port 587 for SMTP with StartTLS:

Set Variable [$r; Value:MBS("SendMail.SetSMTPServer"; $EmailID; "smtp://mail.yourdomain.com:587")]

Use alternative port 465 for SMTP with TLS:

Set Variable [$r; Value:MBS("SendMail.SetSMTPServer"; $EmailID; "smtp://mail.yourdomain.com:465")]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 3th September 2014, last changed 17th November 2023


SendMail.SetSMTPPassword - SendMail.SetSMTPUserName