Shoutbox.net is a Developer API designed to send transactional emails at scale. This documentation covers all Python integration methods, from direct API calls to full framework integration.
There are four main ways to integrate with Shoutbox in Python:
- Direct API calls (minimal dependencies)
- Using our Python library with pip
- SMTP integration
- Web framework integration (Flask/Django)
If you want minimal dependencies, you can make direct API calls using requests
:
import requests
# Your API key from Shoutbox.net
api_key = 'your-api-key-here'
# Prepare email data
data = {
'from': '[email protected]',
'to': '[email protected]',
'subject': 'Test Email',
'html': '<h1>Hello!</h1><p>This is a test email.</p>',
'name': 'Sender Name',
'reply_to': '[email protected]'
}
# Make the API call
response = requests.post(
'https://api.shoutbox.net/send',
headers={
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
},
json=data
)
# Handle the response
if response.status_code >= 200 and response.status_code < 300:
print("Email sent successfully!")
else:
print(f"Failed to send email. Status code: {response.status_code}")
- Minimal dependencies (only requests)
- Simple implementation
- Full control over the request
- Lightweight integration
- Suitable for simple implementations
pip install shoutbox
The API client provides an object-oriented interface to the REST API:
from shoutbox import ShoutboxClient, Email, EmailAddress, Attachment
# Initialize client
api_key = os.getenv('SHOUTBOX_API_KEY') or 'your-api-key-here'
client = ShoutboxClient(api_key)
try:
# Basic email
email = Email(
from_email="[email protected]",
to="[email protected]",
subject="Test Email",
html="<h1>Hello!</h1><p>This is a test email.</p>",
reply_to="[email protected]"
)
client.send(email)
# Email with attachments
email_with_attachments = Email(
from_email="[email protected]",
to="[email protected]",
subject="Test Email with Attachments",
html="<h1>Hello!</h1><p>This email includes attachments.</p>",
attachments=[
# Just provide the filepath - content and type are handled automatically
Attachment(filepath="path/to/document.pdf"),
Attachment(filepath="path/to/spreadsheet.xlsx")
]
)
client.send(email_with_attachments)
# You can still attach content directly if needed
attachment = Attachment(
filename='custom.txt',
content=b"Custom content",
content_type='text/plain'
)
email_with_custom = Email(
from_email="[email protected]",
to="[email protected]",
subject="Test Email with Custom Attachment",
html="<h1>Hello!</h1><p>This email includes a custom attachment.</p>",
attachments=[attachment]
)
client.send(email_with_custom)
except Exception as e:
print(f"Error: {str(e)}")
The SMTP client provides an alternative way to send emails:
from shoutbox import SMTPClient, Email
client = SMTPClient('your-api-key-here')
try:
# Multiple recipients
email = Email(
from_email="[email protected]",
to=["[email protected]", "[email protected]"],
subject="Test Email",
html="<h1>Hello!</h1><p>This is a test email.</p>",
headers={
'X-Custom-Header': 'Custom Value',
'X-Priority': '1'
}
)
client.send(email)
except Exception as e:
print(f"Error: {str(e)}")
- Type-safe email options
- Built-in error handling
- Simple file attachment support (just provide filepath)
- Custom headers support
- Multiple recipient types (to, cc, bcc)
- Choice between API and SMTP clients
from flask import Flask
from shoutbox import ShoutboxClient, Email
app = Flask(__name__)
client = ShoutboxClient(api_key='your-api-key')
@app.route('/send-email', methods=['POST'])
def send_email():
email = Email(
from_email="[email protected]",
to=request.json['to'],
subject=request.json['subject'],
html=request.json['html']
)
result = client.send(email)
return {'success': True}
- Add configuration to
settings.py
:
SHOUTBOX_API_KEY = 'your-api-key'
- Usage example:
from shoutbox import ShoutboxClient, Email
client = ShoutboxClient()
def send_notification(request):
email = Email(
from_email="[email protected]",
to="[email protected]",
subject="Notification",
html="<h1>New notification</h1>"
)
client.send(email)
return JsonResponse({'success': True})
- Clone the repository:
git clone https://github.com/shoutboxnet/shoutbox-python.git
- Install dependencies:
pip install -r requirements-dev.txt
- Run tests:
make test
- GitHub Issues for bug reports
- Email support for critical issues
- Documentation for guides and examples
- Regular updates and maintenance
This library is licensed under the MIT License. See the LICENSE file for details.