简体   繁体   中英

Is it possible to send emails only with the client-side?

I need to send emails in a front-end application that I'm using Vue.js, I would like to know if it's possible to send mail only with Javascript .. or do I need a server-side language for this? Thank you!

所有电子邮件都是通过某种服务器发送的,因此您需要在线使用 API 或托管可以发送和接收邮件的服务器( Gmail 的 API要求您托管服务器)。

It is possible but not practical. You can use smtpjs.com. After you setup all the information, add these to your html:

HTML -> Head:

<script src="https://smtpjs.com/v2/smtp.js"></script>

JS

Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");

If you don't want to send your credentials over http, there's also a way to encrypt it as well.

You can encrypt your SMTP credentials, and lock it to a single domain, and pass a secure token instead of the credentials instead, for example:

Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});

No you can't send an email directly with javascript. But you can open user's mail client like this:

window.open('mailto:abc@example.com?subject=subject&body=body');

Where subject and body are optional parameters. I found it here .

不,您不能从 javascript 或 Html 客户端发送电子邮件,因为它生成的 OTP 页面必须经过验证,然后它必须是服务器或使用任何第三方 API,您可以通过它发送电子邮件。

In theory no, you can not. However, there are options nowadays to send e-mail from the client side using third party services such as FormSpree and EmailJS .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM