20

i was wondering lately how i could send emails with only a front-end language like Javascript through Email as a Service apps like sendgrid or mandrill or so.

Sendgrid and mandrill have Curl APIS, so basically i can just do an AJAX post request to their API to send a mail but the thing is, i will have to put my API secret key in the JS file, this means it will be public... while it's supposed to be secret.

On those two apps, there's nothing in the docs concerning front-end use except having your own server which will use the API, but i'm currently on front-end based project. No server programming, the server only renders the assets that's all.

Do you guys know any method or apps of this kind to acheive this ? Thanks

darkylmnx
  • 1,891
  • 4
  • 22
  • 36
  • For as far as I know is this impossible without showing a secret key. – Robin Aug 17 '15 at 00:43
  • mmmh but doing this with a secret key sets some security problems because anybody could use my key, won't they ? @RobinR – darkylmnx Aug 17 '15 at 00:50
  • That's what I said. It is possible? But when you'll do it without PHP or something else of unreadable client files, it'll be an security issue. – Robin Aug 17 '15 at 00:54
  • 3
    well i found this : http://www.emailjs.com it seems they found a way i guess @RobinR – darkylmnx Aug 17 '15 at 01:00
  • if you also setup automated emails using a different type of third party solution - http://ifttt.com can email you if you use the new Maker channel to monitor a website, it works from a regular POST command. It won't be superreliable but should let you know id there is a problem – Mousey Aug 17 '15 at 02:53
  • the mailto using the end user's client (if they have one) is also possible. – Mousey Aug 17 '15 at 02:53
  • @Mousey the mailto is not automatic and can't send html emails, but thanks for the ifttt i'll check this out – darkylmnx Aug 17 '15 at 15:36

6 Answers6

16

You can use FormSpree. Just provide the url in form action.

https://formspree.io/

Avik
  • 739
  • 9
  • 15
  • Nah, "By default, a user is shown a Formspree "Thank You" page after submission." Have to pay to have a custom form submission page and you're limited to 50 emails/month on the free plan. – Patrick Dec 29 '19 at 18:15
  • Yeah, free tier for this service seems very limited. This is a fully backend based solution, but you pay someone to take care of this backend for you. – M3RS Feb 14 '20 at 11:46
5

Several suugestions

Community
  • 1
  • 1
Mousey
  • 1,855
  • 19
  • 34
  • those are very good alternative solutions thanks ! but for 2 of them i will have to create remotely the form and embed it (which was not the initial idea) and for sendgrid and php, there is some backend code to do (which was not the idea too, but is a good alternative for me but for a front-end only dev not so good alternative), and the key problem is still there, it's public so stealable... but i guess it's like FB or common APIS where you can limit access of the key from a certain host only @mousey – darkylmnx Aug 18 '15 at 22:15
  • @darkylmnx the last option involves writing your own code from scratch but leaves you needing to mask the email address and possibly use encryption and/or SSL. The **third party service** option lets you add extra fields and customise the form, you can build your own form around their suggestions. `OAuth` is an alternative to the API key too, which is what **dropbox forms/jot box** uses – Mousey Aug 18 '15 at 22:39
  • Hi @darkylmnx have you found anything to solve this issue ? – DaniP Jan 18 '17 at 14:38
1

You could use a serverless architecture with AWS Lambda functions written in JavaScript.

M3RS
  • 6,720
  • 6
  • 37
  • 47
  • well that would mean I'd need to code, which I didn't want, i'm looking for tools to do front-end-only development. Apparently Mailchimp has an api for that but there's still some backend code needed which is a pain. – darkylmnx Feb 15 '20 at 14:59
1

You can use Smtp.js or emailjs for frontend.

SaimumIslam27
  • 971
  • 1
  • 8
  • 14
0

If you'd like to keep the key secure you can use something like Aerobatic's HTTP Proxy to specify the key and proxy through the server environment.

Ivan -Oats- Storck
  • 4,096
  • 3
  • 30
  • 39
0

An alternative is to let each user use his or her own outgoing mail server, by using a mailto: link, which allows you to specify the header information and also a quasi-header named “body”, which puts the content you want into the message body.

Jonathan Pool
  • 369
  • 1
  • 9
  • 1
    I don't think if that would be the most optimal solution here. The user would be sending a mail to himself. That's not professional way of doing things. – Daman Arora May 29 '21 at 18:13