Hedwig
public struct Hedwig
Hedwig is the manager type of Hedwig framework. You can initialize an instance with common SMTP config and then send an email with it.
-
Initialize a Hedwig instance with SMTP config.
Note
Initializing a
Hedwig
instance will not do the actual connecting work. It will not try to connect to server until you send a mail.Declaration
Parameters
hostName
Hostname of your SMTP server. The host name should not include any scheme. For example,
smtp.example.com
is a valid host name.user
User name used to auth with SMTP server. Pass
nil
to this parameter if there is no need to auth with your server.password
Password used to auth with SMTP server. Pass
nil
to this parameter if there is no need to auth with your server.port
Port number which Hedwig should connect to. Default is
nil
, which means Hedwig will determine the port for you according tosecure
parameter and use the standard port.secure
Security level used when communicating with server. Default is
.tls
.validation
Validation used when setup a secure connection with server.
domainName
The clinet domain name used when communicating with server. Default is
localhost
authMethods
Auth methods accepted in client when auth with server. By default all auth methods (.plain, .cramMD5, .login, .xOauth2) in Hedwig are supported.
-
Send a single email.
Declaration
Swift
public func send(_ mail: Mail, completion: ((Error?) -> Void)? = nil)
Parameters
mail
The email which will be sent.
completion
Callback when sending finishes, with an optional
Error
to indicate whether there is an error happened while sending. If the mail is sent successfully, callback parameter would benil
. -
Send an array of emails.
Note
Note:
- If a failure is encountered when while sending multiple mails, the
whole sending process will not stop until all pending mails are sent.
Each mail sending will trigger an invocation of
progress
, and when all mails sending finish,completion
handler will be called. - The parameter of
progress
block contains the mail and an optionalError
. If the mail is sent successfully, the error parameter would benil
. Otherwise, it contains the error type. - The first parameter of
completion
is an array of sucessully sent mails, while the second is an array of failed mails and corresponding errors for each. - This method will queue the
mails
and send them one by one. If you need to send mails in a concurrent way, callsend(_:progress:completion:)
again with another array of mails.
Declaration
Parameters
mails
The emails which will be sent.
progress
Callback when an email sending finishes.
completion
Callback when all emails sending finished.
- If a failure is encountered when while sending multiple mails, the
whole sending process will not stop until all pending mails are sent.
Each mail sending will trigger an invocation of