# Gateway keys

For extra security, we recommend adding a custom SMTP header to each email sent to the email to SMS gateway. The gateway then checks the key as well as the sender's address.

Adding a header doesn't change the subject or body of the email, so it doesn't affect the text message.

## The header

| Header name | Value |
|-------------|-------|
| `X-IFLOW-GWAY-KEY` | Your gateway key, which depends on the account and wildcard being used |
{.table}

> [!WARNING]
> Treat a gateway key like a password. Don't publish it, and don't commit it to source control. The keys below are placeholders.

<!-- NEEDS CAPTURE: where an Iflow user finds or creates their gateway key in the portal. -->

## What the gateway receives

Below is an example of the headers of an email received by the gateway. Some are added in transit or by our own system.

```
MIME-Version: 1.0
From: <user@yourdomain.com>
To: <08xxxxxxx@text.diarybook.com>
Date: Mon, 11 Dec 2017 15:44:49 +0000
Subject: Subject of email
Content-Type: text/plain
X-RCPT-TO: <08xxxxxxxx@text.diarybook.com>
X-IFLOW-GWAY-KEY: lk_gway_xxxxxx_xxxxxxxxxxxxxx
Return-Path: <user@yourdomain.com>
```

## Adding the header

How you add the header depends on your environment. Most have something similar to these.

**.NET (C#)**

```csharp
var mail = new MailMessage();
mail.From = new MailAddress("user@yourdomain.com");
mail.To.Add("08xxxxxxx@text.diarybook.com");
mail.Subject = "Message subject";
mail.Headers.Add("X-IFLOW-GWAY-KEY", "lk_gway_xxxxxx_xxxxxxxxxxxxxx");
```

**Rails**

```ruby
class MyMailer < ActionMailer::Base
  def welcome
    headers['X-IFLOW-GWAY-KEY'] = 'lk_gway_xxxxxx_xxxxxxxxxxxxxx'
    mail to: '08xxxxxxx@text.diarybook.com',
         from: 'user@yourdomain.com',
         subject: ''
  end
end
```

**PHP (Symfony Mailer)**

```php
$email = (new Email())
    ->from('user@yourdomain.com')
    ->to('08xxxxxxx@text.diarybook.com')
    ->text('Your message');
$email->getHeaders()->addTextHeader('X-IFLOW-GWAY-KEY', 'lk_gway_xxxxxx_xxxxxxxxxxxxxx');
```

## Related

- [Send SMS by email](/docs/email-to-sms/send-by-email/)
- [DiaryBook API](/docs/api/http-api/)
- [Users](/docs/account/users/)

---
Source: https://iflow.net/docs/email-to-sms/gateway-keys/
