是否可能仅使用JavaScript发送电子邮件?
是否可能仅使用JavaScript发送电子邮件?
编辑:[警告!] 请注意:
这是一个连接到外部服务器的第三方库,请注意您发送的信息。
在JS上,您可以使用名为smtpjs的库解决问题。
在头部添加以下库:
<script src="https://smtpjs.com/smtp.js"></script>
请使用不带安全性的选项:
Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");
Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});
mail()
函数发送电子邮件,该函数由客户端AJAX触发:https://web.archive.org/web/20130718210439/http://www.devarticles.com/c/a/JavaScript/Sending-Email-with-an-SMTP-Client-Built-with-Prototype-and-PHP/ - Prid可以。使用Web服务。您可以通过AJAX调用服务。 EmailYak是这样的一项服务(目前处于私人测试阶段)。
编辑:这仍然是一种服务器端解决方案,因为实际的电子邮件是从服务器发送的。您只是通过AJAX与服务器通信并告诉它发送电子邮件。
请注意,smtpjs使用位于http://smtpjs的服务。它并不是真正的JavaScript SMTP客户端。这个“工具”意味着您正在将电子邮件凭据上传到服务器smtpjs.com。请极度谨慎使用。
您可以重定向到一个mailto:someone@example.com?cc=someone_else@example.com&subject=This%20is%20the%20subject&body=This%20is%20the%20body
地址,这会告诉浏览器启动邮件客户端并准备好发送邮件 - 用户只需点击“提交”即可。
代码:
document.location="mailto:someone@example.com?cc=someone_else@example.com&"+
"subject=This%20is%20the%20subject&body=This%20is%20the%20body";