我可以使用 JavaScript 发送电子邮件吗

发布于 2024-10-07 18:53:08 字数 33 浏览 0 评论 0原文

是否可以仅使用 javascript 发送电子邮件?

Is it possible to send emails using just javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

累赘 2024-10-14 18:53:08

编辑:[警告!]自述文件:

这是一个连接到外部服务器的第三方库,请小心
以及您发送的信息。


JS 上的另一个解决方案,您可以使用名为 smtpjs 的库,

在标题上添加以下库:

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

使用此无安全性

Email.send("[email protected]",
"[email protected]",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");

使用此有安全性

Email.send("[email protected]",
"[email protected]",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});

EDIT: [WARNING!] README:

It's a third party library that connects to an external server, take care
with the information that you are sending.


Another solution on JS you can use a library named smtpjs

Add following library your html on header:

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

Use this without security:

Email.send("[email protected]",
"[email protected]",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");

Use this with security:

Email.send("[email protected]",
"[email protected]",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});
红墙和绿瓦 2024-10-14 18:53:08

构建一个 Javascript 中的 SMTP 客户端

但该 SMTP 客户端仍需要与 SMTP 服务器通信才能传递其电子邮件。如今,向所有人开放的 SMTP 服务器非常罕见(因为它们很快就会成为垃圾邮件渠道,然后被阻止和/或关闭)。

但是,如果使用客户端的人可以为其提供 SMTP 服务器和用户凭据(就像任何其他通用电子邮件客户端一样),那么是的,您可以仅使用 javascript 发送电子邮件。

It's actually possible and not all that difficult to build an SMTP client in Javascript.

But that SMTP client will still need to talk to an SMTP server for getting its emails delivered. And SMTP servers open to everyone are very rare nowadays (because they quickly become Spam conduits and then blocked and/or closed).

However, if the person using the client can supply an SMTP server and user credentials for it (just like with any other general purpose email client), then yes, you can send emails using just javascript.

病毒体 2024-10-14 18:53:08

是。使用网络服务。您可以对服务进行 AJAX 调用。 EmailYak 就是这样一种服务(现在处于私人测试阶段)。

编辑:
这仍然是服务器端解决方案,因为实际的电子邮件是从服务器发送的。您只是通过 AJAX 与服务器通信并告诉它发送电子邮件。

Yes. Using a Webservice. You can make an AJAX call to the service. EmailYak is one such service (It's in a private beta now).

EDIT:
This is still a server side solution, as the actual email is sent from the server. You are just communicating with a server via AJAX and telling it to send the email.

秋日私语 2024-10-14 18:53:08

请注意,smtpjs 使用位于 http://smtpjs 的服务。它并不是真正的 Javascript SMTP 客户端。此“实用程序”意味着您正在将电子邮件凭据上传到服务器 smtpjs.com。 使用时要格外小心

Note that smtpjs uses a service located at http://smtpjs. It's not truly a Javascript SMTP client. This "utility" means you are uploading your email credentials to the server smtpjs.com. Use with extreme caution.

你与清晨阳光 2024-10-14 18:53:08

您可以重定向到mailto:[电子邮件受保护][电子邮件受保护]&subject=This%20is%20the%20subject&body=这个%20is%20the%20body 地址告诉浏览器启动邮件客户端,然后使邮件准备好发送 - 用户只需点击“提交”即可。

代码:

document.location="mailto:[email protected][email protected]&"+
    "subject=This%20is%20the%20subject&body=This%20is%20the%20body";

You can redirect to a mailto:[email protected][email protected]&subject=This%20is%20the%20subject&body=This%20is%20the%20body address which tells the browser to fire up the mail client which then makes the mail ready to send - the user just has to hit "submit".

Code:

document.location="mailto:[email protected][email protected]&"+
    "subject=This%20is%20the%20subject&body=This%20is%20the%20body";
林空鹿饮溪 2024-10-14 18:53:08

如果您想从 SMTP 进程“静默”发送消息,则需要在服务器上或使用托管服务来完成此操作。

如果您乐意使用用户的本机电子邮件程序,则可以使用此问题中描述的方法

If you want to send the message "silently" from an SMTP process, then this needs to be done on the server or by using a hosted service.

If you are happy to use the user's native email program, you could use an approach such as that described in this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文