我可以使用JavaScript创建客户端电子邮件吗?

时间:2021-11-01 16:25:58

I want to create a client side mail creator web page. I know the problems of using the mailto action in an html form (not standard, no default mail appication set on the client). But the web page isn't very important, and they don't care very much.

我想创建一个客户端邮件创建者网页。我知道在html表单中使用mailto操作的问题(不是标准的,客户端上没有设置默认邮件应用程序)。但网页不是很重要,他们并不在乎。

The mail created by the mailto action has the syntax:

mailto操作创建的邮件具有以下语法:

subject: undefined subject
body:

主题:未定义的主体:

param1=value1
param2=value2
.
.
.
paramn=valuen

param1 = value1 param2 = value2。 。 。 paramn =值N

Can I use JavaScript to format the mail like this?

我可以使用JavaScript来格式化这样的邮件吗?

Subject:XXXXX

Body: Value1;Value2;Value3...ValueN

5 个解决方案

#1


15  

What we used in a projet is a popup window that opens a mailto: link, it is the only way we found to compose a mail within the default mail client that works with all mail clients (at least all our clients used).

我们在projet中使用的是一个打开mailto:链接的弹出窗口,这是我们发现在默认邮件客户端中编写邮件的唯一方式,该邮件客户端适用于所有邮件客户端(至少我们所有客户端都使用过)。

var addresses = "";//between the speech mark goes the receptient. Seperate addresses with a ;
var body = ""//write the message text between the speech marks or put a variable in the place of the speech marks
var subject = ""//between the speech marks goes the subject of the message
var href = "mailto:" + addresses + "?"
         + "subject=" + subject + "&"
         + "body=" + body;
var wndMail;
wndMail = window.open(href, "_blank", "scrollbars=yes,resizable=yes,width=10,height=10");
if(wndMail)
{
    wndMail.close();    
}

#2


6  

You more or less only have two alternatives when sending mail via the browser..

通过浏览器发送邮件时,您或多或少只有两种选择。

  1. make a page that takes user input, and allows them to send the mail via your web-server. You need some kind of server-side scripting for this.
  2. 创建一个接受用户输入的页面,并允许他们通过您的Web服务器发送邮件。您需要某种服务器端脚本。

  3. use a mailto: link to trigger opening of the users registered mail client. This has the obvious pitfalls you mentioned, and is less flexible. It needs less work though.
  4. 使用mailto:link来触发用户注册邮件客户端的打开。这有你提到的明显陷阱,而且灵活性较差。但它需要的工作量更少。

#3


4  

With javascript alone, it's not possible.
Javascript is not intended to do such things and is severely crippled in the way it can interact with anything other than the webbrowser it lives in, (for good reason!).

仅使用javascript,这是不可能的。 Javascript并不打算做这样的事情,并且在它与其所在的Web浏览器之外的任何其他事物的交互方式上严重削弱,(有充分的理由!)。

Think about it: a spammer writing a website with client side javascript which will automatically mail to thousands of random email addresses. If people should go to that site they would all be participating in a distributed mass mailing scam, with their own computer... no infection or user interaction needed!

想一想:垃圾邮件发送者使用客户端javascript编写一个网站,该网站将自动邮寄到数千个随机电子邮件地址。如果人们应该访问该网站,他们将全部参与分布式群发邮件骗局,使用自己的计算机......不需要感染或用户交互!

#4


1  

You can create a mailto-link and fire it using javascript:

您可以使用javascript创建mailto-link并触发它:

  var mail = "mailto:buddy@mail.com?subject=New Mail&body=Mail text body";  
  var mlink = document.createElement('a');
  mlink.setAttribute('href', mail);
  mlink.click();

#5


0  

Is there a reason you can't just send the data to a page which handles sending the mail? It is pretty easy to send an email in most languages, so unless there's a strong reason to push it to client side, I would recommend that route.

您是否有理由不能将数据发送到处理发送邮件的页面?使用大多数语言发送电子邮件非常容易,因此除非有充分的理由将其推送到客户端,否则我会推荐该路由。

#1


15  

What we used in a projet is a popup window that opens a mailto: link, it is the only way we found to compose a mail within the default mail client that works with all mail clients (at least all our clients used).

我们在projet中使用的是一个打开mailto:链接的弹出窗口,这是我们发现在默认邮件客户端中编写邮件的唯一方式,该邮件客户端适用于所有邮件客户端(至少我们所有客户端都使用过)。

var addresses = "";//between the speech mark goes the receptient. Seperate addresses with a ;
var body = ""//write the message text between the speech marks or put a variable in the place of the speech marks
var subject = ""//between the speech marks goes the subject of the message
var href = "mailto:" + addresses + "?"
         + "subject=" + subject + "&"
         + "body=" + body;
var wndMail;
wndMail = window.open(href, "_blank", "scrollbars=yes,resizable=yes,width=10,height=10");
if(wndMail)
{
    wndMail.close();    
}

#2


6  

You more or less only have two alternatives when sending mail via the browser..

通过浏览器发送邮件时,您或多或少只有两种选择。

  1. make a page that takes user input, and allows them to send the mail via your web-server. You need some kind of server-side scripting for this.
  2. 创建一个接受用户输入的页面,并允许他们通过您的Web服务器发送邮件。您需要某种服务器端脚本。

  3. use a mailto: link to trigger opening of the users registered mail client. This has the obvious pitfalls you mentioned, and is less flexible. It needs less work though.
  4. 使用mailto:link来触发用户注册邮件客户端的打开。这有你提到的明显陷阱,而且灵活性较差。但它需要的工作量更少。

#3


4  

With javascript alone, it's not possible.
Javascript is not intended to do such things and is severely crippled in the way it can interact with anything other than the webbrowser it lives in, (for good reason!).

仅使用javascript,这是不可能的。 Javascript并不打算做这样的事情,并且在它与其所在的Web浏览器之外的任何其他事物的交互方式上严重削弱,(有充分的理由!)。

Think about it: a spammer writing a website with client side javascript which will automatically mail to thousands of random email addresses. If people should go to that site they would all be participating in a distributed mass mailing scam, with their own computer... no infection or user interaction needed!

想一想:垃圾邮件发送者使用客户端javascript编写一个网站,该网站将自动邮寄到数千个随机电子邮件地址。如果人们应该访问该网站,他们将全部参与分布式群发邮件骗局,使用自己的计算机......不需要感染或用户交互!

#4


1  

You can create a mailto-link and fire it using javascript:

您可以使用javascript创建mailto-link并触发它:

  var mail = "mailto:buddy@mail.com?subject=New Mail&body=Mail text body";  
  var mlink = document.createElement('a');
  mlink.setAttribute('href', mail);
  mlink.click();

#5


0  

Is there a reason you can't just send the data to a page which handles sending the mail? It is pretty easy to send an email in most languages, so unless there's a strong reason to push it to client side, I would recommend that route.

您是否有理由不能将数据发送到处理发送邮件的页面?使用大多数语言发送电子邮件非常容易,因此除非有充分的理由将其推送到客户端,否则我会推荐该路由。