Skip to content

Instantly share code, notes, and snippets.

@29satnam
Created July 25, 2017 10:18
Show Gist options
  • Save 29satnam/acfdb9f3c34a7b9e19f86ed7335bff0e to your computer and use it in GitHub Desktop.
Save 29satnam/acfdb9f3c34a7b9e19f86ed7335bff0e to your computer and use it in GitHub Desktop.
Swift 3 mailcore2-ios Implementation.
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: "receiver@abc.com")]
builder.header.from = MCOAddress(displayName: "Some Sender Name", mailbox: "sender@abc.com")
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")
}
}
@rajkumar17
Copy link

Hi,
How to add an image within the message body?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment