diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 60c85c82c..d0dcb3052 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -61,27 +61,13 @@ def get(self): if self.template_id is not None: mail["template_id"] = self.template_id - if self.sections is not None: - sections = {} - for key in self.sections: - sections.update(key.get()) - mail["sections"] = sections - - if self.headers is not None: - headers = {} - for key in self.headers: - headers.update(key.get()) - mail["headers"] = headers - + select(self.sections,"sections") + select(self.headers,"headers") if self.categories is not None: mail["categories"] = [category.get() for category in self.categories] - if self.custom_args is not None: - custom_args = {} - for key in self.custom_args: - custom_args.update(key.get()) - mail["custom_args"] = custom_args + select(self.custom_args,"custom_args") if self.send_at is not None: mail["send_at"] = self.send_at @@ -105,6 +91,13 @@ def get(self): mail["reply_to"] = self.reply_to.get() return mail + def select(data,index): + if data is not None: + container = {} + for key in data: + container.update(key.get()) + mail[index] = container + @property def from_email(self): return self._from_email