Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. var smtpSession = MCOSMTPSession()
  2. smtpSession.hostname = ""
  3. smtpSession.username = ""
  4. smtpSession.password = ""
  5. smtpSession.timeout = 5
  6. smtpSession.port = UInt32(port!)!
  7. smtpSession.authType = MCOAuthType.saslPlain
  8. smtpSession.connectionType = MCOConnectionType.startTLS
  9. smtpSession.connectionLogger = {(connectionID, type, data) in
  10. if data != nil {
  11. if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){
  12. NSLog("Connectionlogger: \(string)")
  13. }
  14. }
  15. }
  16.  
  17. var builder = MCOMessageBuilder()
  18. builder.header.to = [MCOAddress(displayName: "Some Receiver Name", mailbox: "receiver@abc.com")]
  19. builder.header.from = MCOAddress(displayName: "Some Sender Name", mailbox: "sender@abc.com")
  20. builder.header.subject = "Some Heading"
  21. builder.htmlBody = "<h1>heading</h1>"
  22. builder.textBody = "Some Text"
  23.  
  24. let rfc822Data = builder.data()
  25. let sendOperation = smtpSession.sendOperation(with: rfc822Data)
  26. sendOperation?.start { (error) -> Void in
  27. if (error != nil) {
  28. print("Error sending email: \(error)")
  29.  
  30.  
  31. } else {
  32. print("Mail Sent")
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement