news-ai / tabulae-site

Frontend for Media List Management platform.
https://tabulae-dev.newsai.co
1 stars 0 forks source link

smtp add #479

Closed AbhiAgarwal closed 7 years ago

AbhiAgarwal commented 7 years ago
  1. POST to https://tabulae.newsai.org/api/email-settings

Sample POST to add SMTP/IMAP settings:

You can tell the user to find this from their email provider (if they use Hotmail or Yahoo Mail or Godaddy they can just Google Godaddy SMTP settings or Godaddy IMTP settings).

{
    "SMTPServer": "smtp.gmail.com",
    "SMTPPortTLS": 587,
    "SMTPPortSSL": 465,
    "SMTPSSLTLS": true,
    "IMAPServer": "imap.gmail.com",
    "IMAPPortTLS": 143,
    "IMAPPortSSL": 993,
    "IMAPSSLTLS": true
}

Keep the ID that this returns. You'll find this ID in the /users/me as field emailsetting.

Sample POST to add username/password for email:

POST to https://tabulae.newsai.org/api/email-settings/add-email

{
"smtpusername":"newsai.alerts.buzzfeed@gmail.com",
"smtppassword":"$i86gZd9*eKFrWk"
}

Ask the user for the email and password. This email doesn't necessarily have to be their (email). It'll send from this address. You can enforce it on the front end for it to be their email. So just be like the user is abhi@newsai.org. And ask them to enter their password. Tell them we won't read their emails, etc. same as gmail.

(You usually wouldn't use Gmail SMTP - you'd have something else, but I only had my private email SMTP). I added this as an example.

After both of these have been added. You can verify if the username/password & connection is valid:

Something like: https://tabulae.newsai.org/api/email-settings/5764952132419584/verify.

This will return a status true or false and an error message. Show the user the error message if it returns false.

If it comes back true, then it'll switch on the boolean flag "smtpvalid": true, in /users/me.

After this is complete and smptvalid is true. Now you can do a PATCH to the user to set the externalemail field for a user to be true. Now, the user will be sending emails through the SMPT rather than through SendGrid or Gmail.

One thing to note: don't let the user have both gmail and smtp on at the same time. It won't really matter - if you have both on it won't cause bugs. But, if they have gmail already enabled don't let them use SMTP and if they have SMTP don't let them use gmail.

juliepanda commented 7 years ago

is this https://tabulae.newsai.org/api/email-settings/:personId/verify or a diff id?

AbhiAgarwal commented 7 years ago

It's the emailsetting ID from users me

AbhiAgarwal commented 7 years ago

The field emailsetting in users/me. If you put that in email-settings/that id/verify