Prompt
I'm building a Python app and need an API to send invoices by email
Latest observation
Oct 4, 2026
OpenAI APIWeb search: off
If you want to send invoices by email from a Python app, the simplest approach is usually:
- Generate the invoice as a PDF
- Email it as an attachment using an email provider API or SMTP
- Optionally track delivery/open status
Good API options
1. SendGrid
- Easy to use from Python
- Good for transactional email
- Supports attachments, templates, analytics
2. Mailgun
- Great for transactional email
- Simple HTTP API
- Good deliverability
3. Amazon SES
- Very cost-effective
- More setup, but scalable
- Good if you already use AWS
4. Postmark
- Very good for transactional emails
- Simple API and strong deliverability
Recommended stack for invoice emails
- PDF generation:
reportlab,WeasyPrint, orwkhtmltopdf - Email sending:
SendGrid/Mailgun/SES - Optional storage: S3 or similar for invoice PDFs
Example: SendGrid in Python
import base64
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Email, To, Content, Attachment, FileContent, FileName, FileType, Disposition
message = Mail(
from_email=Email("billing@yourcompany.com"),
to_emails=To("customer@example.com"),
subject="Your Invoice #12345",
plain_text_content=Content(
"text/plain",
"Hi, please find your invoice attached."
)
)
with open("invoice-12345.pdf", "rb") as f:
encoded_file = base64.b64encode(f.read()).decode()
attachment = Attachment(
FileContent(encoded_file),
FileName("invoice-12345.pdf"),
FileType("application/pdf"),
Disposition("attachment")
)
message.attachment = attachment
sg = SendGridAPIClient("YOUR_SENDGRID_API_KEY")
response = sg.send(message)
print(response.status_code)
Things to consider
- Make sure your invoices are properly branded and compliant
- Use a verified sender domain
- Add error handling and retries
- Store invoice metadata in your DB
- If invoices contain sensitive info, ensure:
- HTTPS
- secure API key storage
- access control
- possibly password-protected PDFs
If you want the easiest recommendation
- SendGrid or Postmark for simplicity
- Amazon SES if cost is most important
If you want, I can also give you:
- a full Python example,
- a FastAPI endpoint for sending invoices,
- or a comparison table of SendGrid vs SES vs Mailgun vs Postmark.