-
Notifications
You must be signed in to change notification settings - Fork 11
/
SMTP.swift
49 lines (39 loc) · 1.2 KB
/
SMTP.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// SMTP.swift
// Perfect-OAuth2-Server
//
// Created by Jonathan Guthrie on 2017-02-07.
//
//
import PerfectSMTP
public struct SMTPConfig {
public static var mailserver = ""
public static var mailuser = ""
public static var mailpass = ""
public static var mailfromname = ""
public static var mailfromaddress = ""
}
public class Utility {
public static func sendMail(name: String = "", address: String, subject: String, html: String = "", text: String = "") {
if html.isEmpty && text.isEmpty { return }
let client = SMTPClient(url: SMTPConfig.mailserver, username: SMTPConfig.mailuser, password: SMTPConfig.mailpass)
let email = EMail(client: client)
email.subject = subject
// set the sender info
email.from = Recipient(name: SMTPConfig.mailfromname, address: SMTPConfig.mailfromaddress)
if !html.isEmpty { email.content = html }
if !text.isEmpty { email.text = text }
email.to.append(Recipient(name: name, address: address))
do {
try email.send { code, header, body in
/// response info from mail server
// print("code: \(code)")
// print("header: \(header)")
// print("body: \(body)")
}
} catch {
print("email.send error: \(error)")
/// something wrong
}
}
}