Created
July 25, 2017 10:18
-
-
Save 29satnam/acfdb9f3c34a7b9e19f86ed7335bff0e to your computer and use it in GitHub Desktop.
Swift 3 mailcore2-ios Implementation.
This file contains hidden or 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 = "" | |
smtpSession.username = "" | |
smtpSession.password = "" | |
smtpSession.timeout = 5 | |
smtpSession.port = UInt32(port!)! | |
smtpSession.authType = MCOAuthType.saslPlain | |
smtpSession.connectionType = MCOConnectionType.startTLS | |
smtpSession.connectionLogger = {(connectionID, type, data) in | |
if data != nil { | |
if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){ | |
NSLog("Connectionlogger: \(string)") | |
} | |
} | |
} | |
var builder = MCOMessageBuilder() | |
builder.header.to = [MCOAddress(displayName: "Some Receiver Name", mailbox: "[email protected]")] | |
builder.header.from = MCOAddress(displayName: "Some Sender Name", mailbox: "[email protected]") | |
builder.header.subject = "Some Heading" | |
builder.htmlBody = "<h1>heading</h1>" | |
builder.textBody = "Some Text" | |
let rfc822Data = builder.data() | |
let sendOperation = smtpSession.sendOperation(with: rfc822Data) | |
sendOperation?.start { (error) -> Void in | |
if (error != nil) { | |
print("Error sending email: \(error)") | |
} else { | |
print("Mail Sent") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
How to add an image within the message body?