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
SMTPinstance.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
hostnameHostname of the SMTP server to connect to, i.e.
smtp.example.com.emailUsername to log in to server.
passwordPassword to log in to server, or access token if using XOAUTH2 authorization method.
portPort to connect to the server on. Defaults to
465.tlsModeTLSMode
enumindicating what form of connection security to use.tlsConfigurationTLSConfigurationused to connect with TLS. If nil, a configuration with no backing certificates is used. SeeTLSConfigurationfor other configuration options.authMethodsAuthMethods to use to log in to the server. If blank, tries all supported methods.domainNameClient domain name used when communicating with the server. Defaults to
localhost.timeoutHow long to try connecting to the server to before returning an error. Defaults to
10seconds. -
Send multiple emails.
Note
Note:
- Each call to
sendwill first log in to your server, attempt to send the mails, then closes the connection. Pass in an array ofMails to send them all in one session. - If any of the email addresses in a
Mail‘sto,cc, orbccare invalid, the entire mail will not send and return anSMTPError. - If an individual
Mailfails while sending an array ofMails, the whole sending process will continue until all pendingMails are attempted. - Each call to
sendqueues it’sMails and sends them one by one. To sendMails concurrently, send them in separate calls tosend.
Declaration
Swift
public func send(_ mails: [Mail], progress: Progress = nil, completion: Completion = nil)Parameters
mailsArray of
Mails to send.progresscompletion - Each call to
View on GitHub
SMTP Structure Reference