我想发送ehlo命令以从smtp服务器获取响应,而不使用任何第三方库。我正在使用TCP流与套接字连接。因此,我想知道如何将“ EHLO”命令发送到服务器并获得响应。
class Connection: NSObject {
static let shared = Connection()
private var inputStream: InputStream!
private var outputStream: OutputStream!
private let maxReadLength = 4096
func setupServerCommunication() {
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
let host = "domain_name" as CFString
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, 25, &readStream, &writeStream)
inputStream = readStream!.takeRetainedValue()
outputStream = writeStream!.takeRetainedValue()
inputStream.schedule(in: .current, forMode: .commonModes)
outputStream.schedule(in: .current, forMode: .commonModes)
inputStream.open()
inputStream.delegate = self
outputStream.open()
}
func quitSession() {
inputStream.close()
outputStream.close()
inputStream.remove(from: .current, forMode: .commonModes)
outputStream.remove(from: .current, forMode: .commonModes)
inputStream = nil
outputStream = nil
}
}