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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4454294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 12:27:42  来源:igfitidea点击:

Can I send email using javascript

javascripthtmlemailsmtpsmtpclient

提问by dotty

Is it possible to send emails using just javascript?

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

采纳答案by Adam

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

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

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.

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

回答by Michael Borgwardt

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

在 Javascript 中构建SMTP 客户端实际上是可能的,而且并不是那么困难。

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).

但是该 SMTP 客户端仍需要与 SMTP 服务器通信才能发送电子邮件。现在对所有人开放的 SMTP 服务器非常罕见(因为它们很快成为垃圾邮件管道,然后被阻止和/或关闭)。

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.

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

回答by mfruizs2

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

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

Add following library your html on header:

在标题上添加以下库您的 html:

<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"});

回答by Joshua Zeidner

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.

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

回答by thejh

You can redirect to a mailto:[email protected][email protected]&subject=This%20is%20the%20subject&body=This%20is%20the%20bodyaddress 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".

你可以重定向到一个mailto:[email protected][email protected]&subject=This%20is%20the%20subject&body=This%20is%20the%20body地址,它告诉浏览器启动邮件客户端,然后让邮件准备好发送——用户只需点击“提交”。

Code:

代码:

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

回答by Phil.Wheeler

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.

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

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

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