For Python I do not see option that allows attaching multiple files to the same email. How to achieve this?
I don't quite understand why this was closed. Are you indicating that the SendGrid API itself doesn't support multiple attachments? And so it's not a Python library issue?
The comment in the original issue was for Python specifically I believe.
This is also the first result I got to for googling "Python sendgrid multiple attachment" (and didn't really answer my question of whether it is possible).
So reading the current source code makes it seem like they've set up the code to do some surprising setter magic (in sendgrid.helpers.mail.Mail:
@property
def attachments(self):
"""The attachments to this email
:rtype: list(Attachment)
"""
return self._attachments
@property
def attachment(self):
pass
@attachment.setter
def attachment(self, attachment):
"""Add attachment(s) to this email
:param attachment: Add attachment(s) to this email
:type attachment: Attachment, list(Attachment)
"""
if isinstance(attachment, list):
for a in attachment:
self.add_attachment(a)
else:
self.add_attachment(attachment)
def add_attachment(self, attachment):
"""Add an attachment to this email
:param attachment: Add an attachment to this email
:type attachment: Attachment
"""
self._attachments = self._ensure_append(attachment, self._attachments)
So you could either have the slightly odd looking client code like this:
mymail.attachment = myattachment1
mymail.attachment = myattachment2
Or the more explicit:
mymail.add_attachment(myattachment1)
mymail.add_attachment(myattachment2)
Or some other shenanigans:
mymail.attachment = [myattachment1, myattachment2]
In any of the above, you likely still need to create the rich Attachment class for each file and all that jazz.
@shea-parkes Good catch. This should not have been closed. Re-opening as docs update needed.
This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.
I would like to provide a minimal working example and work on this issue, can you help to figure out which documentation should I add it to?
I think it belongs to use_cases/attachment.md
@hack3r-0m Yes, there works.
I was able to fulfil my goal of sending with API later on. This can be closed. Thanks