SMTP
public struct SMTP
Used to connect to an SMTP server and send emails.
-
TLSMode enum for what form of connection security to enforce.
See moreDeclaration
Swift
public enum TLSMode
-
Initializes an
SMTP
instance.Note
Note:
- You may need to enable access for less secure apps for your account on the SMTP server.
- Some servers like Gmail support IPv6, and if your network does not, you will first attempt to connect via IPv6, then timeout, and fall back to IPv4. You can avoid this by disabling IPv6 on your machine.
Declaration
Swift
public init(hostname: String, email: String, password: String, port: Int32 = 587, tlsMode: TLSMode = .requireSTARTTLS, tlsConfiguration: TLSConfiguration? = nil, authMethods: [AuthMethod] = [], domainName: String = "localhost", timeout: UInt = 10)
Parameters
hostname
Hostname of the SMTP server to connect to, i.e.
smtp.example.com
.email
Username to log in to server.
password
Password to log in to server, or access token if using XOAUTH2 authorization method.
port
Port to connect to the server on. Defaults to
465
.tlsMode
TLSMode
enum
indicating what form of connection security to use.tlsConfiguration
TLSConfiguration
used to connect with TLS. If nil, a configuration with no backing certificates is used. SeeTLSConfiguration
for other configuration options.authMethods
AuthMethod
s to use to log in to the server. If blank, tries all supported methods.domainName
Client domain name used when communicating with the server. Defaults to
localhost
.timeout
How long to try connecting to the server to before returning an error. Defaults to
10
seconds. -
Send multiple emails.
Note
Note:
- Each call to
send
will first log in to your server, attempt to send the mails, then closes the connection. Pass in an array ofMail
s to send them all in one session. - If any of the email addresses in a
Mail
‘sto
,cc
, orbcc
are invalid, the entire mail will not send and return anSMTPError
. - If an individual
Mail
fails while sending an array ofMail
s, the whole sending process will continue until all pendingMail
s are attempted. - Each call to
send
queues it’sMail
s and sends them one by one. To sendMail
s concurrently, send them in separate calls tosend
.
Declaration
Swift
public func send(_ mails: [Mail], progress: Progress = nil, completion: Completion = nil)
Parameters
mails
Array of
Mail
s to send.progress
completion
- Each call to