Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 邮件未使用平均堆栈应用程序正确发送_Angular - Fatal编程技术网

Angular 邮件未使用平均堆栈应用程序正确发送

Angular 邮件未使用平均堆栈应用程序正确发送,angular,Angular,我有这样的问题。我正在使用mean stack应用程序创建自动发送电子邮件功能 这是后端的index.js文件 const express = require('express'); const bodyParser = require('body-parser'); const passport = require('passport'); const cors = require('cors'); const path = require('path'); var app = expr

我有这样的问题。我正在使用mean stack应用程序创建自动发送电子邮件功能

这是后端的index.js文件

const express = require('express');
const  bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');

const path = require('path');

var app = express();
const config = require('./db.js');
require('./config/passport')(passport);

var userController = require('./controllers/userController');
var reservationController = require('./controllers/reservationController');
var mailController = require('./controllers/mailController');

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(passport.initialize());
app.use(passport.session());
app.use(cors({ origin: 'http://localhost:4200'}));



app.listen(3000, function ( ) {
    console.log('Server started at port : 3000')
});

app.use('/user', userController);
app.use('/reservation', reservationController);
app.use('/mail', mailController);
这里我提供了我的邮件控制器文件

const express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'labreservation123@gmail.com',
        pass: 'a@##1234'
    }
});


router.post("/sendmail", function (req, res) {
    const email= req.body.email;
    console.log(email);
    console.log('hii');
    var mailOptions = {
        from: 'labreservation123@gmail.com',
        to: 'tharindusandaruwan40@gmail.com',
        subject: 'Sending Email using Node.js',
        text: 'That was easy!'
    }

    transporter.sendMail(mailOptions, function(error, info){
        if (error) {
            console.log(error);
        } else {
            res.json(info.response);
        }
    });

});

module.exports = router;
当我和邮递员核对时,它工作正常。但是,当我尝试使用我的前端时,它不会发送任何信息,甚至不会记录问候语

这是我的服务文件

import { Injectable } from '@angular/core';
import { HttpClient , HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import {Reservation} from "./reservation";

@Injectable()
export class ReservationService {
  public selectedReservation: Reservation = new Reservation();
  public  reservations: Reservation[];
  public  removedReservations: Reservation[];
  public cCount:any;
  public rCount:any;
  public uCount:any;
  constructor(private http: HttpClient) { }

  getNotConfirmedReservationList(){
    return this.http.get('http://localhost:3000/reservation/notComfirmed');
  }

  confirm(_id: string){
    let headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/reservation/confirm',{_id} , {headers: headers});
  }

  remove(_id: string){
    let headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/reservation/remove',{_id} , {headers: headers});
  }

  getallReservationList(){
    return this.http.get('http://localhost:3000/reservation');
  }

  getallRemoved(){
    return this.http.get('http://localhost:3000/reservation/removed');
  }

  getCCount(){
    return this.http.get('http://localhost:3000/reservation/cCount');
  }

  getRCount(){
    return this.http.get('http://localhost:3000/reservation/rCount');
  }

  getUCount(){
    return this.http.get('http://localhost:3000/reservation/uCount');
  }

  getItem(_id: string){
    let headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/reservation/item',{_id} , {headers: headers});
  }

  sendMail(email:string){
    let headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/mail/sendmail',{email},{headers: headers});
  }


}
在这里,我提供了我调用此电子邮件功能的特定component.ts文件

import { Component, OnInit } from '@angular/core';
import { UserService} from '../../shared/user.service';
import {Router} from "@angular/router";
import {ReservationService} from '../../shared/reservation.service';
import { FlashMessagesService } from 'angular2-flash-messages';

//
import { Reservation } from '../../shared/reservation';
// import {AlertService} from "ngx-alerts";


@Component({
  selector: 'app-adminpannel',
  templateUrl: './adminpannel.component.html',
  styleUrls: ['./adminpannel.component.css'],
  providers: [UserService,ReservationService]
})
export class AdminpannelComponent implements OnInit {
  reservation:any;
  constructor(private userService: UserService,private router: Router, private reservationService: ReservationService, private flashMessage:FlashMessagesService) { }

  ngOnInit() {
    if(this.userService.loggedIn()) {
      this.userService.getProfile().subscribe(res => {
        console.log(res)
      })
    }

    this.getNotConfirmedReservations();
    this.getCCount();
    this.getRCount();
    this.getUCount();
  }



  getNotConfirmedReservations(){
    this.reservationService.getNotConfirmedReservationList().subscribe( (res) => {
      this.reservationService.reservations = res as Reservation[];
    });
  }

  confirm(id){
    this.reservationService.confirm(id).subscribe( (res) => {
      this.reservationService.getItem(id).subscribe((res)=>{
        this.reservationService.selectedReservation=res as Reservation;
        this.reservation=this.reservationService.selectedReservation;
        this.reservationService.sendMail(this.reservation.email);
      });
      this.flashMessage.show("Succesfully confirmed" , {cssClass: 'alert-succes', delay: 1000});
      this.getNotConfirmedReservations();
      // this.router.navigate(['/admin']);
    });
  }

  remove(id){
    this.reservationService.remove(id).subscribe( (res) => {
      this.flashMessage.show("Succesfully removed" , {cssClass: 'alert-danger', delay: 1000});
      this.getNotConfirmedReservations();

    });
  }

  getCCount(){
    this.reservationService.getCCount().subscribe((res)=>{
      this.reservationService.cCount=res;
    })
  }

  getRCount(){
    this.reservationService.getRCount().subscribe((res)=>{
      this.reservationService.rCount=res;
    })
  }

  getUCount(){
    this.reservationService.getUCount().subscribe((res)=>{
      this.reservationService.uCount=res;
    })
  }


}

有人能帮我解决这个问题并正确发送邮件吗?。谢谢

您是否正确设置了端口、ssl和凭据?是的,所有这些都是正确的。当我在你的前端(角度)用postmanon试用它时,它工作正常,你在控制台上遇到任何错误吗?没有,那里没有显示任何错误。