Sending AngularJS form to NodeMailer to send email

前端 未结 2 1958
北荒
北荒 2021-01-22 15:52

I have a built an email form in a modal instance using AngularJS that contains the field sending email, recipient email, subject, and email content. The form uses input boxes an

2条回答
  •  逝去的感伤
    2021-01-22 16:04

    At the node side you can create a REST end point in order to recieve a POST request from the server for the form submission of email in the modal box. The REST end-point will look like this if you have an express server.

    var express = require('express');
    var router = express.Router();
    var app = express();
    app.post('/postEmail',function(req,res){
        //Your NodeMailer logic comes here
    });
    

    In the angular part, just like you have written a service, you can create an angular factory to invoke this REST end point.

    For example:

    myApp.factory('postEmailForm',['$http',function($http){
       return {
         postEmail: function(emailData,callback){
           $http.post("/postEmail/", emailData).success(callback);  
         }
       }
    }]);
    

    where myApp is your angular module, emailData is the emailForm data which you want to send to the server (it will be posted in the body of the request)

提交回复
热议问题