4

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("vkxyz@abc.com",
                "vk@nyu.edu",
                "This is a subject",
                "this is the body",
                "smtp.qwe.io",
                "vkxyz@abc.com",
                "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

Manoj Kalluri
  • 1,384
  • 2
  • 14
  • 27
  • You may want to take a look at [EmailJS](http://emailjs.com?src=so), which allows sending email using pre-built templates directly from Javascript [disclosure - I'm one of the creators] – Sasha Oct 26 '17 at 13:06
  • @Sasha, actually I need and SMTP client to send emails. at my enterprise we need to use SMTP server to send email. but when I'm googling most of the answers are we can't use SMTP with JS to send emails. EmailJS don't have this . – Manoj Kalluri Oct 31 '17 at 14:53
  • EmailJS.com does allow you to connect your own SMTP server and use it for the outgoing emails. I would suggest signing up and taking a look at our dashboard - please feel free to reach out to our support for help, if needed. – Sasha Oct 31 '17 at 18:09

4 Answers4

11

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

Manoj Kalluri
  • 1,384
  • 2
  • 14
  • 27
3

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.

Coder66
  • 67
  • 8
0

Guys this answer is for web user as I implement it in javascript code. I used the smtpjs for it. The code in my js file is this -

Email.send("sendermailid@xyz.com", <--(1) 
receivermailid@xyz.com,            <--(2)  
"subject of mail",                 <--(3)   
"This is the body",                <--(4)  
"app.smtp2go.com",                 <--(5) 
"samtradesster@gmail.com",         <--(6)  
"############");                   <--(7) 

First, go to site https://smtpjs.com/ for cdn of smtpjs. Then see,

  1. is sender emailed who will send mail
  2. is the receiver emailed who will receiver sender's mail?
  3. is subject of the mail.
  4. is Body of mail.Same as Gmail body.
  5. is your SMTP server provider which here is app.smtp2go.com.
  6. is account name of SMTP server provider site.
  7. is a password in SMTP server provider site account eg; I have an account name is "samtradesster@gmail.com", and password is something random.

At last here is link for SMTP server provider is https://app.smtp2go.com

wscourge
  • 10,657
  • 14
  • 59
  • 80
Himanshu Joshi
  • 100
  • 1
  • 5
0

I was having similar issues, what help was setting up "Sign in with App Passwords" on my google account.

Here is how to do it https://support.google.com/accounts/answer/185833?hl=en

Sign in with App Passwords

Tip: App Passwords aren’t recommended and are unnecessary in most cases. To help keep your account secure, use "Sign in with Google" to connect apps to your Google Account.

An App Password is a 16-digit passcode that gives a less secure app or device permission to access your Google Account. App Passwords can only be used with accounts that have 2-Step Verification turned on.

When to use App Passwords

Tip: iPhones and iPads with iOS 11 or up don’t require App Passwords. Instead use “Sign in with Google.”

If the app doesn’t offer “Sign in with Google,” you can either:

Use App Passwords

Switch to a more secure app or device Create & use App Passwords If you use 2-Step-Verification and get a "password incorrect" error when you sign in, you can try to use an App Password.

Go to your Google Account. Select Security. Under "Signing in to Google," select App Passwords. You may need to sign in. If you don’t have this option, it might be because: 2-Step Verification is not set up for your account. 2-Step Verification is only set up for security keys. Your account is through work, school, or other organization. You turned on Advanced Protection. At the bottom, choose Select app and choose the app you using and then Select device and choose the device you’re using and then Generate. Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device. Tap Done.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 08 '22 at 20:35