Skip to content

Commit

Permalink
Merge pull request #34 from saicu/master
Browse files Browse the repository at this point in the history
fix for sending without template data
  • Loading branch information
twof authored Aug 27, 2019
2 parents 08d8921 + 383c085 commit 9c41e74
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/Mailgun/Models/TemplateMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ extension Mailgun {
try container.encode(bcc, forKey: .bcc)
try container.encode(subject, forKey: .subject)
try container.encode(template, forKey: .template)
guard let jsonData = try? JSONEncoder().encode(templateData), let jsonString = String(data: jsonData, encoding: .utf8) else {
throw Error.encodingProblem
if let templateData = templateData {
guard let jsonData = try? JSONEncoder().encode(templateData), let jsonString = String(data: jsonData, encoding: .utf8) else {
throw Error.encodingProblem
}
try container.encode(jsonString, forKey: .templateData)
}
try container.encode(jsonString, forKey: .templateData)
try container.encode(templateVersion, forKey: .templateVersion)
let text = templateText == true ? "yes" : nil // need to send yes as string
try container.encode(text, forKey: .templateText)
Expand Down

0 comments on commit 9c41e74

Please sign in to comment.