Anvil-app-server noob questions

Few questions regarding the Anvil-app-server:

  1. Does table data get transferred when cloning the app? Specifically the Users table with passwords but also any other data I have entered in my App through Anvil.works?
  2. I cannot get password reset emails to send. Is there an SMTP log anywhere to check for errors?
    config settings used:

smtp-host: “smtp.myhost.co.uk
smtp-port: “465”
smtp-encryption: true
smtp-username: “me@mydomain.co.uk
smtp-password: “mypassshhh!”

  1. –config-file. Docs state “All other options are specified as strings” would this include numeric values eg. smtp-port: “465” or smtp-port: 465?
  2. –auto-migrate. what does this do?

Thanks.

Re question 1: From Security Notes:

Note that using a clone link will always share the latest version of the app, including the content of all Data Tables.

(Emphasis mine.)

Please try smtp-port: 465 in the config file, using – has a bug at the moment

As for data, it is not transfered in my cases, I installed and reinstalled servers million times. Will check again and let you know the result

Thanks, I tried that still not working.

Could you confirm I’m using “smtp-encryption:” correctly.

Docs say:
" --smtp-encryption Use TLS to connect to SMTP server"
“smtp-encryption Enable TLS for connecting to outbound SMTP server (see smtp-host ).”

I assumed it was a simple true/false to use TLS. I put “smtp-encryption: true” in my config file.

However I have seen “smtp-encryption: ssl” being used in GIT issue number #8 so I am unsure I understand the correct syntax.

I am not too sure why it doesn’t work since someone confirm it works in the above-mentioned link
The smtp-encryption: true seems to be true as well.

It seems there are several bugs at the moment since I cannot make the remote database work as well

No, the tables do not get cloned.

The term ‘clone’ is used in two different contexts within Anvil. When you clone an app within Anvil itself (using the clone link), everything is copied, including the tables.

However, for the app server, you are using git to clone the source code (only) for your app and that’s a completely different mechanism.

2 Likes

Using the standalone app server, you have to provide your own smtp server. You don’t have access the built-in server at Anvil. Settings like:

smtp-host: “smtp.myhost.co.uk”

are just an example and need to be replaced by whatever is appropriate for your own server.

Yeah, didn’t think it was a good idea to post my real SMTP details on a public forum! :slight_smile:

1 Like

Ah. Sorry. I’ve just re-read your original post and realised I’d misunderstood your question!

When you (git) clone your app, it will include a file named anvil.yaml which contains, amongst other things, the schema definition of any data tables. This flag means that the server will read that definition and create those tables in your local copy. Note - the tables will have no content.

1 Like

Still cannot get the SMTP settings to work. but I now get the following error:

  2020-06-02 19:04:21,500 [ERROR anvil.app-server.run] Error report from client code:
  AnvilWrappedError: Invalid Addresses
  Traceback:
      <rpc>:0

  anvil-services/anvil/users.py:63

  anvil-services/anvil/users.py:469

  anvil-services/anvil/users.py:469

  app/CC_Test/Form1/__init__.py:15

But I believe I have might have found some answers by looking into code I don’t entirely understand. And on that basis please excuse me if I’m talking complete rubbish!

  1. smtp-encryption: option will accept the following values “ssl” or “starttls”.

    From email.clj line 227:

    (defn smtp-send [{:keys [host port user pass encryption] :as _smtp-config}
    {:keys [from-address from-name to cc bcc subject text html attachments inline-
    attachments in-reply-to references app-id] :as _message}]

    (when-not host
    (throw+ {:anvil/server-error “No SMTP server has been configured for this app”}))

    (let [session (Session/getInstance (make-props (merge {“mail.smtp.starttls.enable” (if (contains? #
    {“ssl” “starttls”} encryption) “true” “false”)}
    (when (= encryption “starttls”)
    {“mail.smtp.starttls.required” “true”}))))

  2. It appears that the smtp email “from account” might be hard coded to “accounts” which would make the “Invalid Addresses” error make sense as it is not a valid user on my email host.

From core.clj Line 232:

(defn send-email! [to subject text]
  (if (get-in @util/*session-state* [:users :test-email-divert])
    (swap! util/*session-state* update-in [:users :test-email-divert] concat [{:to to, :subject subject, :text text}])
    (binding [email/*use-quota* false
              email/*require-service-config* false]
      (email/send! {:from_name    (if (app-data/abuse-caution? util/*session-state* util/*app-id*)
                                    "Accounts"
                                    (str (:name util/*app*) " Accounts"))
                    :from_address "accounts"
                    :to           to
                    :subject      subject
                    :text         text}))))

Can someone check if I am understanding the code correctly and if my conclusion is correct.

Hi @apearce, Does yout solution in the below link work? Thanks

No, but it get’s me to the next problem (see AnvilWrappedError: Invalid Addresses) which might be due to hard coding of the “from-address” as “accounts”.

Thanks for the update
Does it work if you remove smtp-encryption from the configuration file?

No. it gives the error:

2020-06-04 09:03:38,183 [ERROR anvil.app-server.run] Error report from client code:
AnvilWrappedError: Could not connect to SMTP host: smtp.livemail.co.uk, port: 465, response: -1
Traceback:
  <rpc>:0

  anvil-services/anvil/users.py:63

  anvil-services/anvil/users.py:469

  anvil-services/anvil/users.py:469

  app/CC_Test/Form1/__init__.py:15

I am confident that the first two smtp issues I had are dealt with:

  1. smtp-port: 465 (must be entered as numeric)
  2. smtp-encryption: (must entered as “ssl” in my case, “starttls” is also an option)

The error I’m getting now I believe is due to the “from-address” not being the same as my smtp user.

There needs to be an option to set the “from-address” which in my case needs to be the same as the “smtp-user” (“myaccount@mydomain.co.uk”).

My host does not allow different “from-address” (or alias) to the smtp user. I think Anvil might be hard coding “accounts” as the from address.

I have posted a new topic to address that.

This topic is now answered.

A follow-up topic on another anvil-app-server smtp error can be found here.

Thanks

So is there a way to move your current (on the Anvil server) data tables to your new (app-server) data tables?

Move? Not that I know of. Copy, yes, in principle. I wrote a backup routine that writes to a SQLite database. (Search this forum for SQLite.) It preserves row-ids.

When adding a row to a new table, of course, brand-new row-ids will be created, guaranteed to be different from the original. So, if there are any references to such a row, via row-id, you’d need to translate those references (row ids) from the old scheme to the new.

Of course, once it’s copied, you could delete the original data, so I suppose that would count as a “move”.

1 Like

Thanks… the issue is that I have a working app on the Anvil servers, but I’m trying out the Anvil App Server installed on Google Compute, both to learn something and to have a backup. I got it up and running, but it generated an error when it tried to read a table with no entries. That’s when I realized that git cloning didn’t copy the tables…