如何使用javascript以HTML格式发送电子邮件

问题描述:

如何使用javascript / ajax发送电子邮件..没有服务器端代码



实际上我想使用gmail或yahoo api ..我搜索但是可以找不到..



},



任何人都可以帮助我..

How to send email in HTML using javascript/ajax..No server side code

Actually i want to use gmail or yahoo api.. I searched but could not find..

},

Can anyone help me..

首先,您需要生成需要在mandrill中注册的密钥..



为此,请按照以下步骤操作链接:



First of All you need to generate key for that you need to register in mandrill..

For this follow the below link:

https://medium.com/@mariusc23/send-an-email-using-only-javascript-b53319616782


<html>
<head>
    <title></title>
    <style type="text/css">
        #btnsend
        {
            width: 125px;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td>
                &nbsp;From:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="txtfrom" />
            </td>
        </tr>
        <tr>
        <td>
            Subject:&nbsp; <input type="text" id="txtsubject" />
            </td>

        </tr>
        <tr>
            <td>
                TO:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="txtto" />
            </td>
            <br /

        </tr>
        <tr>
            <td>
                <input type="button" id="btnsend" value="Submit" /><br />
            </td>
        </tr>
    </table>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">


.ajax({
类型:POST,
url:https://mandrillapp.com/api/1.0/messages/send.json,
数据:{
'key':' XXXXXXXXXXXXXXX',
'消息':{
'来自m_email':'你的邮件ID',
'到':[
{
'电子邮件':'收件人邮件ID',
'名称':'姓名',
'type':'to'
}
],
'autotext':'true',
'subject':'你的主题在这里!',
'html':'Body'
}
}
})。done(function(response){
console.log(response);
});

< / script >
< / body >
< / html >
.ajax({ type: "POST", url: "https://mandrillapp.com/api/1.0/messages/send.json", data: { 'key': 'XXXXXXXXXXXXXXX', 'message': { 'from_email': 'your mail id', 'to': [ { 'email': 'receiver mail id', 'name': 'Name', 'type': 'to' } ], 'autotext': 'true', 'subject': 'YOUR SUBJECT HERE!', 'html': 'Body' } } }).done(function (response) { console.log(response); }); </script> </body> </html>


JavaScript 是基于客户端的,所以不具备服务器上的C#

你有唯一的 mailto 功能,你可以在客户端使用 HTML 。它打开用户系统中安装的默认邮件客户端。



阅读 JavaScript可以通过电子邮件发送表单吗? [ ^ ]
JavaScript is client based, so doesn't have the capabilities like C# on the server.
You have the only mailto feature, which you can use at client side using HTML. It opens the default mail client installed in the user's system.

Read Can JavaScript email a form?[^]