# SMTP usernames with backslash?

**URL:** https://meta.discourse.org/t/smtp-usernames-with-backslash/38337
**Category:** Self-hosting
**Created:** [January 22, 2016, 1:41pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337 "2016-01-22T13:41:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Knud](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Knud](https://meta.discourse.org/u/Knud)
#### Post date: [January 22, 2016, 1:41pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337/1 "2016-01-22T13:41:45Z")

</div>

Dear all,

I’m trying to set up Discourse on a virtual server. I can use the organisation’s SMTP-server for mail, so that is fine and I got everything set-up, except for one proplem: no emails are being sent. I then created an admin account with

`./launcher enter app`  
`rake admin:create`

which nicely worked, and then looked at the mail setting. There I found the likely reason that no emails are being sent: my SMTP username is of the form “foo\bar”, where “foo” is a given prefix for a subgroup of users on that system, and “bar” is my account name. Then there is the backslash in between.

When I look at the /admin/email page in my Discourse installation, what I get shown as user\_name is “foobar” without the backslash. I then tried escaping in app.yml, after looking up YAML syntax.

I tried:

```
DISCOURSE_SMTP_USER_NAME: foo\bar
DISCOURSE_SMTP_USER_NAME: 'foo\bar'
DISCOURSE_SMTP_USER_NAME: "foo\\bar"
DISCOURSE_SMTP_USER_NAME: foo\\bar

```

All give the same result (after rebuilding Discourse every time): `user_name: foobar`

I don’t know where the backslash might get stripped. I saw no warning on special characters but the escaping I tried did not result in a change at Discourse installation level. I tried sending an email every time after rebuild (from the /admin/email page) but I always receive an error when sending.

Can someone help, please?

---

<div class="post-metadata">

### Author: ![wesochuck](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wesochuck/32/108706_2.png) [@wesochuck](https://meta.discourse.org/u/wesochuck)
#### Post date: [January 22, 2016, 2:42pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337/2 "2016-01-22T14:42:34Z")

</div>

If you’re authenticating against a modern windows domain infrastructure, you can probably use the bar@foo format.

> <https://serverfault.com/questions/371150/any-difference-between-domain-username-and-usernamedomain-local>

Otherwise it looks like quotes (double quotes) is the proper method:

> <https://stackoverflow.com/questions/11301650/how-to-escape-indicator-characters-colon-and-hyphen-in-yaml>

If neither work, your organisation might be blocking the ports you need to SMTP from your Discourse box.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [January 22, 2016, 4:34pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337/3 "2016-01-22T16:34:17Z")

</div>

I’m wondering if escaping the backslash once is enough.

In my limited experience with JavaScript, it depends on how many times the string is passed around. eg.

step one → step two → step three  
foo\\bar → foo\bar → foobar

Maybe try foo\\\\bar ?

step one → step two → step three  
foo\\\\bar → foo\\bar → foo\bar

---

<div class="post-metadata">

### Author: ![Knud](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Knud](https://meta.discourse.org/u/Knud)
#### Post date: [January 22, 2016, 10:55pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337/4 "2016-01-22T22:55:08Z")

</div>

Thank you for the hints. Whether they will work I don’t know because some additional issues with the SMTP account came up. But, that said, bar@foo.local is at least parsed properly in the /admin/mail tab. However, also only if enclosed in double quotes `"bar@foo.local"`. Else only `bar@foo` arrives.

@Mittineague: Inside double quotes I’ll need to escape a backslash likely twice, but I’ll test that later.

Currently I’m battling that I did some configuration as admin and for the second time only get a blank screen. 1st time this happened I could not get Discourse back and had to do a complete reinstall… Different topic.

---

<div class="post-metadata">

### Author: ![Knud](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@Knud](https://meta.discourse.org/u/Knud)
#### Post date: [February 10, 2016, 10:44pm UTC](https://meta.discourse.org/t/smtp-usernames-with-backslash/38337/5 "2016-02-10T22:44:10Z")

</div>

So 4 backslashes were needed. Thanks again. Still have email issues, but not because of the backslash 😉
