Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SmtpJs API not working! is there any way to send emails using SMTP server with JavaScript or JQuery

I have an application with JS , Jquery and NoSQL DB . I don't have any backend technology such as Node or C# . my web UI directly interacts with DataBase.

Now after submitting data to DB, I want to send email notifications to users. I searched on internet and there are some articles which say we can't send emails with client side code as we deal with SMTP server.

the fallowing is from smtpjs.com

<script src="js/smtp.js"></script>
<script>
     Email.send("[email protected]",
                "[email protected]",
                "This is a subject",
                "this is the body",
                "smtp.qwe.io",
                "[email protected]",
                "abcq4#");
</script>

the above snippet is not working. tried some other snippets available on internet but nothing works.

By the way my SMTP server has firewall and accepts from local network only. I din't get any connection error log with above code.

so is it possible to send email with JavaScript Jquery , if so please kindly suggest the best practice

Thanks in Advance

like image 279
V K Avatar asked Dec 14 '22 20:12

V K


2 Answers

It is not possible to send emails using SMTP servers with JS or Jquery.

There is no way to hit SMTP server directly from our browsers.

EmailJS or SMTPJs gives us API but eventually we are using their servers to hit the SMTP. actually we are sending data to their server which further sends data to SMTP servers.

So we must need a server to send to SMTP. and we can use NodeJs,C#,Python or Java to do this.

In my case I even tried EmailJs , but my SMTP server blocks EmailJs server IP address.

If you are using enterpise SMTP server , in no way you can email through browser JS & Jquery. you must use a server in backend and write some code in NodeJS etc...

Thanks & correct me If I am wrong

like image 129
V K Avatar answered Dec 26 '22 15:12

V K


Try using Elastic Email. It works with Smtp.js. I have used it before, and it has, for the most part, worked. Also, make sure you are using the latest versions of both.

like image 43
Coder66 Avatar answered Dec 26 '22 17:12

Coder66