We currently have a workflow where users submit data by sending an email to a custom incoming email address, creating a staged user and a private message to a Discourse group.
Is it possible to achieve the same workflow using API calls? Basically 1) create staged user, 2) generate API key for that user, then 3) post on that users behalf? I see how to post group messages for existing users using the API docs, but don’t know if steps 1) and 2) are possible currently.
I’m trying to avoid creating a full-fledged user account and picking a username. Essentially I want to replicate whatever is happening in the email trigger (‘custom incoming email address’ in the group settings) where the sender’s email address will be ‘staged,’ such that if/when they do register, they’ll be able to claim any messages that were created on their behalf via the email trigger.
Does that make sense? Is there a way to ‘spoof’ an incoming email using API calls? Thanks for all your help!
Thank you, Blake. However, it still doesn’t work for me. I got a response from API “email has been received and is queued for processing”, but nothing appears in Discourse - neither a new topic, nor a staged user.
Here’s the review of the settings:
Custom incoming email address: set as [my_name]@gmail.com
Accept emails from anonymous users with no accounts: on
API call: curl -i -sS -X POST "[my_domain]/admin/email/handle_mail" -H "Content-Type: multipart/form-data;" -H "Api-Key: [...]" -H "Api-Username: system" -F "email=Date: Mon, 24 Feb 2020 13:13:34 -0700 From: [some_name]@gmail.com To: [my_name]@gmail.com Subject: test API email post This is a sample email message."
You can check if sidekiq is running by browsing to /sidekiq, but I think there is likely an issue with the raw email now that the api request is succeeding. There are several tabs in the admin dashboard you can check for email errors.
See if you can find the emails you are creating via api calls under one of those tabs and you might be able do see an error message associated with it.
I inserted the same email text in the “Advanced text” tab, and it seems to be working, if each part (Date, From, To, Subject) starts with a new line, and the body is separated by two line breaks. When inserting the text exactly like in curl, it returns nothing. Could it be the line breaks in the raw email? If yes, what should I do?
You were right - that was a newline issue. I tried the same API call from Postman, and it worked - a new staged user was created and a topic on his behalf.
But: no email was sent to this user’s address! I also posted a comment in the topic - no email notification either. Is there a setting that prevents this? I tried to find one, but I couldn’t.
UPD: There was a indeed a setting that prevented sending post notifications so now I have two different questions:
Why there wasn’t an email informing the staged user that the topic was created and sending him the link to it?
(I would also add some instructions about how to log in to the forum if I knew, which template to edit.)
Why there’s no link to the topic in the post notification emails? Also no unsubscribe link.
The template seems to be the same - “user_posted”.
Which setting for anyone following along? I don’t think I had to change anything, so just curious.
I think this is by design and the same happens if you send an email to a Discourse group. It is designed to work just like email as in the user might not even know they are sending an email into a Discourse forum. If I send you a regular email to your email account I don’t get a reply back from your email provider that says you received my email, we just trust that it works.
Here is an example email notification a staged user will receive:
By design there are several fields that are omitted for staged users in email templates (like the respond instructions):
I’m not entirely sure of the reasoning, jut stating that in code this is how it is, so you are currently fighting an up hill battle here because you are attempting to do something discourse is designed not to do.
Yes, you can edit the email templates, but you are pretty limited in what you can customize. Like I don’t think you can customize the email template to look one way for staged users and another way for non-staged users, but you can add a message with a link to the bottom of the notification email inviting them to visit your site instead of just interacting via email.