Unable to get SMTP function to work

Dear Reader,

I have a problem with the SMTP function in vaultwarden (also with passbolt, tried it if i could get that to work). I have a microsoft exchange account, and I have a SendGrid that I used to get SMTP to work. both of them don’t work. I use the latest variant of Vaultwarden.

SMTP Settings in admin portal:
Enabled
Default: true
Host: smtp.office365.com
Secure SMTP: starttls
Port: 587
From Address: email address
From Name: Vaultwarden
Username: email address
Password: “the password of the mailaddress”
SMTP Auth mechanism: “Login”
SMTP connection timeout: 15
Server name sent during HELO: -

I have SMTP enabled on the Office account and I have enabled basic authentications. Still nothing.

I get 2 errors:
[2022-09-17 08:19:25.440][vaultwarden::mail][ERROR] SMTP Connection error: Cannot assign requested address (os error 99)
[2022-09-17 08:19:25.441][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request

With kind regards,
Mathijs

Looks like a hostname resolving issues.
Could you post the Support String which you can generate from the diagnostics page?

Your environment (Generated via diagnostics page)

  • Vaultwarden version: v1.25.2
  • Web-vault version: v2022.6.2
  • Running within Docker: true (Base: Debian)
  • Environment settings overridden: true
  • Uses a reverse proxy: true
  • IP Header check: true (X-Real-IP)
  • Internet access: true
  • Internet access via a proxy: false
  • DNS Check: true
  • Time Check: true
  • Domain Configuration Check: false
  • HTTPS Check: true
  • Database type: SQLite
  • Database version: 3.35.4
  • Clients used:
  • Reverse proxy and version:
  • Other relevant information:

Config (Generated via diagnostics page)

Show Running Config

Environment settings which are overridden: SIGNUPS_ALLOWED, SIGNUPS_VERIFY, ADMIN_TOKEN

{
  "_duo_akey": null,
  "_enable_duo": false,
  "_enable_email_2fa": false,
  "_enable_smtp": true,
  "_enable_yubico": true,
  "_icon_service_csp": "",
  "_icon_service_url": "",
  "_ip_header_enabled": true,
  "admin_ratelimit_max_burst": 3,
  "admin_ratelimit_seconds": 300,
  "admin_token": "***",
  "allowed_iframe_ancestors": "",
  "attachments_folder": "data/attachments",
  "authenticator_disable_time_drift": false,
  "data_folder": "data",
  "database_conn_init": "",
  "database_max_conns": 10,
  "database_timeout": 30,
  "database_url": "****/**.*******",
  "db_connection_retries": 15,
  "disable_2fa_remember": false,
  "disable_admin_token": false,
  "disable_icon_download": false,
  "domain": "*****://********.**",
  "domain_origin": "*****://********.**",
  "domain_path": "",
  "domain_set": true,
  "duo_host": null,
  "duo_ikey": null,
  "duo_skey": null,
  "email_attempts_limit": 3,
  "email_expiration_time": 600,
  "email_token_size": 6,
  "emergency_access_allowed": true,
  "emergency_notification_reminder_schedule": "0 5 * * * *",
  "emergency_request_timeout_schedule": "0 5 * * * *",
  "enable_db_wal": true,
  "extended_logging": true,
  "helo_name": null,
  "hibp_api_key": null,
  "icon_blacklist_non_global_ips": true,
  "icon_blacklist_regex": null,
  "icon_cache_folder": "data/icon_cache",
  "icon_cache_negttl": 259200,
  "icon_cache_ttl": 2592000,
  "icon_download_timeout": 10,
  "icon_redirect_code": 302,
  "icon_service": "internal",
  "incomplete_2fa_schedule": "30 * * * * *",
  "incomplete_2fa_time_limit": 3,
  "invitation_org_name": "Vaultwarden",
  "invitations_allowed": true,
  "ip_header": "X-Real-IP",
  "job_poll_interval_ms": 30000,
  "log_file": null,
  "log_level": "Info",
  "log_timestamp_format": "%Y-%m-%d %H:%M:%S.%3f",
  "login_ratelimit_max_burst": 10,
  "login_ratelimit_seconds": 60,
  "org_attachment_limit": null,
  "org_creation_users": "",
  "password_hints_allowed": true,
  "password_iterations": 100000,
  "reload_templates": false,
  "require_device_email": false,
  "rsa_key_filename": "data/rsa_key",
  "send_purge_schedule": "0 5 * * * *",
  "sends_allowed": true,
  "sends_folder": "data/sends",
  "show_password_hint": false,
  "signups_allowed": true,
  "signups_domains_whitelist": "",
  "signups_verify": false,
  "signups_verify_resend_limit": 6,
  "signups_verify_resend_time": 3600,
  "smtp_accept_invalid_certs": false,
  "smtp_accept_invalid_hostnames": false,
  "smtp_auth_mechanism": "\"Login\"",
  "smtp_debug": false,
  "smtp_explicit_tls": null,
  "smtp_from": "*****@********.**",
  "smtp_from_name": "relay",
  "smtp_host": "****.*********.***",
  "smtp_password": "***",
  "smtp_port": 587,
  "smtp_security": "starttls",
  "smtp_ssl": null,
  "smtp_timeout": 15,
  "smtp_username": "*****@********.**",
  "templates_folder": "data/templates",
  "tmp_folder": "data/tmp",
  "trash_auto_delete_days": null,
  "trash_purge_schedule": "0 5 0 * * *",
  "use_syslog": true,
  "user_attachment_limit": null,
  "web_vault_enabled": true,
  "web_vault_folder": "web-vault/",
  "websocket_address": "0.0.0.0",
  "websocket_enabled": false,
  "websocket_port": 3012,
  "yubico_client_id": null,
  "yubico_secret_key": null,
  "yubico_server": null
}

Please try to enable debug logging.
LOG_LEVEL=debug (or trace) and SMTP_DEBUG=true .

Then try again, and see what the output of the logs tell.

[2022-09-17 13:55:17.830][request][INFO] GET /alive
[2022-09-17 13:55:17.831][response][INFO] (alive) GET /alive => 200 OK
[2022-09-17 13:55:47.112][vaultwarden::api::core::two_factor][DEBUG] Sending notifications for incomplete 2FA logins
[2022-09-17 13:55:57.215][vaultwarden::mail][DEBUG] SMTP lettre::transport::smtp::Error {
kind: Connection,
source: Os {
code: 99,
kind: AddrNotAvailable,
message: “Cannot assign requested address”,
},
}
[2022-09-17 13:55:57.215][vaultwarden::mail][ERROR] SMTP Connection error: Cannot assign requested address (os error 99)
[2022-09-17 13:55:57.216][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request
[2022-09-17 13:56:17.920][request][INFO] GET /alive
[2022-09-17 13:56:17.920][response][INFO] (alive) GET /alive => 200 OK

Still, it looks like resolving the domain seems to have some issues.
Could you run the following from the docker host and see if that works?

docker exec vaultwarden getent hosts smtp.office365.com
# And
docker exec vaultwarden getent ahosts smtp.office365.com

Where vaultwarden is the name of your container of course.

I just tested sendgrid my self, and it works just fine for me.

I am not allowed to post more links because I am a new user, so I uploaded a screenshot

Ik could be me, but I’m not seeing any ipv4 addresses. It could be that your docker config is having issues with ipv6 maybe??

I also changed your user level, so links should be possible now.

version: “2”
services:
vaultwarden:
image: vaultwarden/server:latest
container_name: vaultwarden
volumes:
- /home/docker/VW:/data/
ports:
-8080:80
networks:
ngx:
ipv4_address: 172.19.0.3
restart: unless-stopped
environment:
- LOG_LEVEL=debug
- SMTP_DEBUG=true
- SIGNUPS_ALLOWED=true
- USE_SYSLOG=true
- SIGNUPS_VERIFY=false
- EXTENDED_LOGGING=true
- ADMIN_TOKEN=password
networks:
ngx:
external: true

This is my docker-compose.yml

Hmm, i think it had something to do with ipv6. Like, it tries to use ipv6, but it can’t connect to it and causes this failure.

Maybe try to add the following to the compose file.

    sysctls:
      - "net.ipv6.conf.all.disable_ipv6=1"

That should disable all ipv6 within the container, maybe that will help.

[2022-09-18 06:49:08.263][vaultwarden::mail][ERROR] SMTP Connection error: Cannot assign requested address (os error 99)
[2022-09-18 06:49:08.264][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request
[2022-09-18 06:49:08.264][_][WARN] Remote left: client disconnect before response started.
[2022-09-18 06:49:54.536][vaultwarden::api::core::two_factor][DEBUG] Sending notifications for incomplete 2FA logins
[2022-09-18 06:49:54.751][request][INFO] GET /alive
[2022-09-18 06:49:54.752][response][INFO] (alive) GET /alive => 200 OK
[2022-09-18 06:50:07.835][vaultwarden::mail][DEBUG] SMTP lettre::transport::smtp::Error {
kind: Connection,
source: Os {
code: 99,
kind: AddrNotAvailable,
message: “Cannot assign requested address”,
},
}
[2022-09-18 06:50:07.835][vaultwarden::mail][ERROR] SMTP Connection error: Cannot assign requested address (os error 99)
[2022-09-18 06:50:07.836][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request
Again… Same error

Very strange. Still looks like it can’t resolve or either connect to the ip for some reason.

Could you set the logging to trace and see if that provides some more info.

[2022-09-18 08:09:22.249][vaultwarden::mail][DEBUG] SMTP lettre::transport::smtp::Error {
kind: Connection,
source: Os {
code: 99,
kind: AddrNotAvailable,
message: “Cannot assign requested address”,
},
}
[2022-09-18 08:09:22.249][vaultwarden::mail][ERROR] SMTP Connection error: Cannot assign requested address (os error 99)
[2022-09-18 08:09:22.250][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request
[2022-09-18 08:09:22.250][tracing::span][TRACE] encode_headers;
[2022-09-18 08:09:22.250][tracing::span::active][TRACE] → encode_headers;
[2022-09-18 08:09:22.250][tracing::span::active][TRACE] ← encode_headers;
[2022-09-18 08:09:22.250][tracing::span][TRACE] – encode_headers;
[2022-09-18 08:09:22.250][mio::poll][TRACE] deregistering event source from poller

Do I need to put “” or around the smtp address or is it just plain text?

Just plain/text is more then enough, no quotes needed.
Same goes for all others btw, unless there are some special characters in there or spaces, which for domains and email addresses isn’t the case.

And for the authentication?

Of you refer to smtp_auth_mechanism, that can be without quotes too, but that shouldn’t matter that much.

hmm. Should we try a different smtp service provider? maybe we get more info than that of office365.

with the smtp settings for sendgrid i get this:
[2022-09-18 10:11:42.616][request][INFO] GET /alive
[2022-09-18 10:11:42.616][response][INFO] (alive) GET /alive => 200 OK
[2022-09-18 10:12:03.178][vaultwarden::mail][DEBUG] SMTP timeout error: lettre::transport::smtp::Error {
kind: Connection,
source: Custom {
kind: TimedOut,
error: “connection timed out”,
},
}
[2022-09-18 10:12:03.179][vaultwarden::mail][ERROR] SMTP timeout error: Connection error: connection timed out
[2022-09-18 10:12:03.180][response][INFO] (test_smtp) POST /admin/test/smtp => 400 Bad Request

Enabled: true
Host: smtp.sendgrid.net
Secure SMTP: starttls
Port: 587
From Address: relay@domain.com
From Name: relay
Username: apikey
Password: “the api key”
SMTP Auth mechanism: “Login”
SMTP connection timeout: 15