             self.headers = nil
             self.addHeaders(keyValuePairs)
         }
+        
+        func addAttachment(filename: String, data: NSData) {
+            if self.attachments == nil {
+                self.attachments = [filename: data]
+            } else {
+                self.attachments![filename] = data
+            }
+        }
     }
 }
        addToParamsIfPresent("replyto", email.replyto)
        addToParamsIfPresent("headers", email.headers)
        
        var body = ""
        for (paramName, paramValue) in params {
            if paramName == "headers" {
                if countElements(body) > 0 { body += "&" }
                var error: NSError?
                var data = NSJSONSerialization.dataWithJSONObject(paramValue, options: nil, error: &error)
                if let err = error {
                    Logger.error("Error converting headers to JSON - \(err.localizedDescription)")
                } else if let d = data {
                    if let json = NSString(data: d, encoding: NSUTF8StringEncoding) {
                        if let encoded = json.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
                            body += "headers=\(encoded)"
                        }
                    }
                }
            }else if let arr = paramValue as? [String] {
                for value in arr {
                    if let encoded = value.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
                        if countElements(body) > 0 { body += "&" }
                        body += paramName + "[]=" + encoded
                    }
                }
            } else {
                if let encoded = paramValue.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
                    if countElements(body) > 0 { body += "&" }
                    body += paramName + "=" + encoded
                }
            }
        }
        
        // SMTPAPI
        if email.smtpapi.hasSmtpApi {
            body += "&x-smtpapi=" + email.smtpapi.jsonValue.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
        }
        
        println(body)
        
        request.HTTPBody = body.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        let queue:NSOperationQueue = NSOperationQueue()
        //        NSURLConnection.sendAsynchronousRequest(request, queue: queue) { (response, data, error) -> Void in
        //            if let handler = completionHandler {
        //                handler(response, data, error)
        //            }
        //        }
    }
    
    

                        println("[**ERROR**] SendGrid addTos: The number of email addresses provided didn't match the number of names provided.")
                        return
                    }
                } else if self.toname != nil {
                    self.toname?.append("")
                }
                
                self.to! += addresses
