Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create named sessions without mailgun #3

Open
pperle opened this issue Mar 27, 2020 · 2 comments
Open

create named sessions without mailgun #3

pperle opened this issue Mar 27, 2020 · 2 comments

Comments

@pperle
Copy link

pperle commented Mar 27, 2020

Hey,
I am trying to host my own tmate server.

Everything expect named sessions is working fine.

When I register for an API key I get an error that my mailgun API key is not working. This is right because I do not own a mailgun API key.

** (exit) an exception was raised:
     ** (Bamboo.ApiError) There was a problem sending the email through the Mailgun API.

When I look in postgres a user has been created with an API key.

tmate=# SELECT * FROM users;
                  id                  |             email             | username |            api_key             | verified | allow_mailing_list |     created_at      | last_seen_at 
--------------------------------------+-------------------------------+----------+--------------------------------+----------+--------------------+---------------------+--------------
 b8117e0a-704c-11ea-a9cb-0242ac1c0004 | [email protected]       | test     | tmk-Q2s0h36VrzVcufk2gDVm8w5Opr | f        | t                  | 2020-03-27 17:02:19 | 

When I try to use this api_key to create a named session using tmate -k tmk-JpeKMdFDH21ogA5ekHbfWwN6Jn -n session-name I get this error message:

token=[test/session-name] id=6cfc466c-7050-11ea-ad13-0242ac1c0005 [info] Session started stoken=test/session-name stoken_ro=ro-6FKs... ssh_only=false foreground=false named=true
token=[test/session-name] id=6cfc466c-7050-11ea-ad13-0242ac1c0005 [error] GenServer #PID<0.1364.0> terminating
** (MatchError) no match of right hand side value: {:error, :enoent}
    (tmate) lib/tmate/session.ex:183: Tmate.Session.rename_tmux_sockets!/4
    (tmate) lib/tmate/session.ex:311: Tmate.Session.finalize_session_init/1
    (tmate) lib/tmate/session.ex:131: Tmate.Session.handle_call/3
    (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.1363.0>): {:notify_daemon_msg, [1, '\t']}

:ok = File.rename(p.(old_stoken), p.(stoken))

Is this related to the mailgun API error? Maybe the user was not full created?

Thank you for your help

@1xyz
Copy link

1xyz commented Feb 12, 2021

fwiw - As I understand this -- this is not related to mailgun.

the error no match of right hand side value: {:error, :enoent} is thrown https://github.com/tmate-io/tmate-websocket/blob/master/lib/tmate/session.ex#L183

  • enoent indicates the session file that the tmate-websocket service is trying to rename is not found.
  • the no match of right hand side value is thrown because of == :ok (i.e error case is not checked)

The root cause of this error: the sessions directory /tmp/tmate/sessions is mounted and shared between two containers tmate-websocket and tmate-ssh-server. I suspect your setup may not have had it shared/mounted.

@pini-gh
Copy link

pini-gh commented Mar 2, 2021

Hi,
Mailgun is not mandatory to send emails. I've had some success tweaking the configuration to use my SMTP server with these changes:

diff --git a/config/prod.exs b/config/prod.exs
index 4566092..b029444 100644
--- a/config/prod.exs
+++ b/config/prod.exs
@@ -76,6 +76,8 @@ config :tmate, Tmate.Scheduler,
   ]
 
 config :tmate, Tmate.Mailer,
-  adapter: Bamboo.MailgunAdapter,
-  api_key: System.get_env("MAILGUN_API_KEY"),
-  domain: System.get_env("MAILGUN_DOMAIN")
+  adapter: Bamboo.SMTPAdapter,
+  server: System.get_env("SMTP_HOST"),
+  port: System.get_env("SMTP_PORT"),
+  hostname: System.get_env("SMTP_DOMAIN"),
+  from: System.get_env("EMAIL_FROM")
diff --git a/lib/tmate_web/emails/email.ex b/lib/tmate_web/emails/email.ex
index fd89786..1dd9a5c 100644
--- a/lib/tmate_web/emails/email.ex
+++ b/lib/tmate_web/emails/email.ex
@@ -12,7 +12,7 @@ defmodule Tmate.Email do
 
   defp base_email do
     new_email()
-    |> from("tmate <[email protected]>")
+    |> from(Application.fetch_env!(:tmate, Tmate.Mailer)[:from])
     |> put_html_layout({TmateWeb.LayoutView, "email.html"})
   end
 end
diff --git a/mix.exs b/mix.exs
index e829b21..77f4789 100644
--- a/mix.exs
+++ b/mix.exs
@@ -54,6 +54,7 @@ defmodule Tmate.MixProject do
       {:timex, "~> 3.0"},
       {:httpoison, ">= 0.0.0"},
       {:bamboo, "~> 1.3"},
+      {:bamboo_smtp, "~> 3.0.0"},
     ]
   end
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants