Created
July 26, 2016 18:36
-
-
Save 29satnam/9208215c5250090424be2f2a51896f3b to your computer and use it in GitHub Desktop.
SMTP Block Example Swift iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var smtpSession = MCOSMTPSession() | |
smtpSession.hostname = "HOSTNAME" | |
smtpSession.username = "USERNAME" | |
smtpSession.password = "PASSWORD" | |
smtpSession.port = PORT | |
smtpSession.authType = MCOAuthType.SASLPlain | |
smtpSession.connectionType = MCOConnectionType.TLS | |
smtpSession.connectionLogger = {(connectionID, type, data) in | |
if data != nil { | |
if let string = NSString(data: data, encoding: NSUTF8StringEncoding){ | |
NSLog("Connectionlogger: \(string)") | |
} | |
} | |
} | |
var builder = MCOMessageBuilder() | |
builder.header.to = [MCOAddress(displayName: "Rool", mailbox: "RECEIVER")] | |
builder.header.from = MCOAddress(displayName: "Matt R", mailbox: "SENDER") | |
builder.header.subject = "My message" | |
builder.htmlBody = "<h3>Yo Rool, this is a test message!</h3>" | |
let rfc822Data = builder.data() | |
let sendOperation = smtpSession.sendOperationWithData(rfc822Data) | |
sendOperation.start { (error) -> Void in | |
if (error != nil) { | |
NSLog("Error sending email: \(error)") | |
} else { | |
NSLog("Successfully sent email!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment