具有环回3的电子邮件连接器

问题描述 投票:0回答:1

我有一个联系表单,并使用PersistedModel存储在mysql表中。现在我想发送包含表单值的电子邮件。这该怎么做。我尝试使用loopback 3电子邮件连接器,但没有任何工作,我不知道该怎么做。任何人都可以给我一个例子。

 <form class="form-area contact-form text-right" name="myForm" id="myForm"  novalidate >
                     <div class="row">
                        <div class="col-lg-6 form-group">
                           <input name="name" id="name" placeholder="Enter your name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your name'" class="common-input mb-20 form-control" required="" type="text">
                           <input name="email" id="email" placeholder="Enter email address" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'" class="common-input mb-20 form-control" required="" type="email">
                            <div class="invalid-feedback">Please Enter a Valid Email Id.</div>
                           <input name="subject" id="subject" placeholder="Enter your subject" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your subject'" class="common-input mb-20 form-control" required="" type="text">
                           <div class="mt-20 alert-msg" style="text-align: left;"></div>
                        </div>
                        <div class="col-lg-6 form-group">
                           <textarea class="common-textarea form-control" name="message" id="message" placeholder="Message" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Message'" required=""></textarea>
                           <button type="submit" class="primary-btn mt-20 text-white" style="float: right;">Send Message</button>
                        </div>
                     </div>
                 </form>

脚本:

<script type='text/javascript'>
         $("#myForm").submit(function(e) {
            var ins_date=new Date($.now()).toLocaleString();
         var parms = {
         name : $("#name").val(),
         email : $("#email").val(),
         subject : $("#subject").val(),
         message: $("#message").val(),
         inserted_date:ins_date
         };
         var url2="http://localhost:3000/api";
         $.ajax({
         method: 'POST',
         url: url2 + "/contacts",
         async: false,
         dataType : "json",
         contentType: "application/json; charset=utf-8",
         data: JSON.stringify(parms),
         success: function(result){
         console.log('Submission was successful.');
         location.reload();
         console.log(data);
         }, error: function (data) {
            console.log('An error occurred.');
            console.log(data);
               },   
            })
      });
      </script>

datasource.json

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "mysql": {
    "host": "localhost",
    "port": 3306,
    "url": "",
    "database": "mydb",
    "password": "pass",
    "name": "mysql",
    "user": "root",
    "connector": "mysql"
  },
 "email": {
    "name": "email",
    "connector": "mail",
    "transports": [
      {
        "type": "smtp",
        "host": "mail.company.com",
        "secure": true,
        "port": 465,
        "tls": {
          "rejectUnauthorized": false
        },
        "auth": {
          "user": "[email protected]",
          "pass": "password"
        }
      }
    ]
  }
}
node.js email loopbackjs strongloop loopback
1个回答
0
投票

在环回中添加电子邮件数据源。在afterRemote函数中编写发送电子邮件功能。

© www.soinside.com 2019 - 2024. All rights reserved.