> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usesendly.app/llms.txt
> Use this file to discover all available pages before exploring further.

# SMTP Integration

> Send emails via SMTP

## SMTP Configuration

Use Sendly's SMTP server to send emails from your applications:

### Connection Details

```
Host: smtp.usesendly.app
Port: 587 (TLS) or 465 (SSL)
Username: your-api-key
Password: your-api-key
```

## JavaScript/Node.js

### Using Nodemailer

<CodeGroup>
  ```bash npm theme={null}
  npm install nodemailer
  ```

  ```bash yarn theme={null}
  yarn add nodemailer
  ```
</CodeGroup>

```javascript theme={null}
import nodemailer from 'nodemailer'

const transporter = nodemailer.createTransport({
  host: 'smtp.usesendly.app',
  port: 587,
  secure: false,
  auth: {
    user: 'se_your_api_key',
    pass: 'se_your_api_key'
  }
})

await transporter.sendMail({
  from: 'noreply@yourdomain.com',
  to: 'user@example.com',
  subject: 'Welcome!',
  html: '<h1>Hello!</h1><p>Thanks for signing up.</p>'
})
```

## Python

### Using Django

```python theme={null}
# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.usesendly.app'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'se_your_api_key'
EMAIL_HOST_PASSWORD = 'se_your_api_key'
DEFAULT_FROM_EMAIL = 'noreply@yourdomain.com'
```

Then send emails:

```python theme={null}
from django.core.mail import send_mail

send_mail(
    'Welcome!',
    'Thanks for signing up.',
    'noreply@yourdomain.com',
    ['user@example.com'],
    html_message='<h1>Hello!</h1><p>Thanks for signing up.</p>',
    fail_silently=False,
)
```

### Using Flask-Mail

<CodeGroup>
  ```bash pip theme={null}
  pip install Flask-Mail
  ```
</CodeGroup>

```python theme={null}
from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.usesendly.app'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'se_your_api_key'
app.config['MAIL_PASSWORD'] = 'se_your_api_key'

mail = Mail(app)

msg = Message(
    'Welcome!',
    sender='noreply@yourdomain.com',
    recipients=['user@example.com'],
    html='<h1>Hello!</h1><p>Thanks for signing up.</p>'
)
mail.send(msg)
```

## PHP

### Using PHPMailer

<CodeGroup>
  ```bash composer theme={null}
  composer require phpmailer/phpmailer
  ```
</CodeGroup>

```php theme={null}
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host = 'smtp.usesendly.app';
    $mail->SMTPAuth = true;
    $mail->Username = 'se_your_api_key';
    $mail->Password = 'se_your_api_key';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587;

    $mail->setFrom('noreply@yourdomain.com', 'Your Name');
    $mail->addAddress('user@example.com');

    $mail->isHTML(true);
    $mail->Subject = 'Welcome!';
    $mail->Body = '<h1>Hello!</h1><p>Thanks for signing up.</p>';

    $mail->send();
    echo 'Email sent successfully';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
```

## Ruby

### Using Rails ActionMailer

```ruby theme={null}
# config/environments/production.rb
Rails.application.configure do
  config.action_mailer.smtp_settings = {
    address: 'smtp.usesendly.app',
    port: 587,
    user_name: 'se_your_api_key',
    password: 'se_your_api_key',
    authentication: 'plain',
    enable_starttls_auto: true
  }
end
```

```ruby theme={null}
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
  default from: 'noreply@yourdomain.com'

  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: 'Welcome!')
  end
end
```

## Laravel

### Using Laravel Mail

```php theme={null}
// config/mail.php
'mailers' => [
    'sendly' => [
        'transport' => 'smtp',
        'host' => 'smtp.usesendly.app',
        'port' => 587,
        'encryption' => 'tls',
        'username' => 'se_your_api_key',
        'password' => 'se_your_api_key',
    ],
],

'from' => [
    'address' => 'noreply@yourdomain.com',
    'name' => 'Your App',
],
```

```php theme={null}
// Send email
Mail::to('user@example.com')
    ->send(new WelcomeMail());
```

## Supabase

### Using Supabase Email

```sql theme={null}
-- Enable the email extension
create extension if not exists "http" with schema extensions;

-- Send email via SMTP
select
  extensions.http_post(
    'https://api.usesendly.app/v1/emails',
    json_build_object(
      'from', 'noreply@yourdomain.com',
      'to', 'user@example.com',
      'subject', 'Welcome!',
      'html', '<h1>Hello!</h1><p>Thanks for signing up.</p>'
    )::text,
    'application/json',
    json_build_object(
      'Authorization', 'Bearer se_your_api_key'
    )
  ) as request_id;
```

## Go

### Using Gomail

<CodeGroup>
  ```bash go theme={null}
  go get gopkg.in/mail.v2
  ```
</CodeGroup>

```go theme={null}
package main

import (
	"gopkg.in/mail.v2"
)

func main() {
	d := mail.NewDialer("smtp.usesendly.app", 587, "se_your_api_key", "se_your_api_key")

	m := mail.NewMessage()
	m.SetHeader("From", "noreply@yourdomain.com")
	m.SetHeader("To", "user@example.com")
	m.SetHeader("Subject", "Welcome!")
	m.SetBody("text/html", "<h1>Hello!</h1><p>Thanks for signing up.</p>")

	if err := d.DialAndSend(m); err != nil {
		panic(err)
	}
}
```

## Troubleshooting

### Connection Issues

```
Error: Could not connect to SMTP server
```

**Solution**: Check your firewall allows outbound connections on port 587 or 465.

### Authentication Failed

```
Error: Authentication failed
```

**Solution**: Verify your API key is correct in the MAIL\_USERNAME and MAIL\_PASSWORD fields.

### TLS/SSL Issues

```
Error: TLS negotiation failed
```

**Solution**: Try both port 587 with STARTTLS and port 465 with SSL.

## Resources

* [SDK Integration](/integration/sdk)
* [cURL Integration](/integration/curl)
* [Best Practices](/best-practices)

***

Need help? Contact [support@usesendly.app](mailto:support@usesendly.app)
