diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 116afb46e..0bd83042b 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -82,28 +82,17 @@ def get(self): if self.template_id is not None: mail["template_id"] = self.template_id - if self.sections: - sections = {} - for key in self.sections: - sections.update(key.get()) - mail["sections"] = sections - - if self.headers: - headers = {} - for key in self.headers: - headers.update(key.get()) - mail["headers"] = headers + for attribute in [(self.sections, "sections"), (self.headers, "headers"), (self.custom_args, "custom_args")]: + if attribute[0] is not None: + tmp = {} + for key in attribute[0]: + tmp.update(key.get()) + mail[attribute[1]] = tmp if self.categories: mail["categories"] = [category.get() for category in self.categories] - if self.custom_args: - custom_args = {} - for key in self.custom_args: - custom_args.update(key.get()) - mail["custom_args"] = custom_args - if self.send_at is not None: mail["send_at"] = self.send_at