我正在Angular中开发我的第一个应用程序。我想通过联系表格发送电子邮件,但是出现一个错误,我不了解其来源。
server.js
import cv2
import numpy as np
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray,0,255,cv2.THRESH_OTSU + cv2.THRESH_BINARY)[1]
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
total = 0
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
mask = np.zeros(image.shape, dtype=np.uint8)
cv2.fillPoly(mask, [c], [255,255,255])
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
pixels = cv2.countNonZero(mask)
total += pixels
cv2.putText(image, '{}'.format(pixels), (x,y - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,255,255), 2)
print(total)
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey(0)
routes.js文件的内容:
var nodemailer = require('nodemailer');
const http = require("http");
const cors = require("cors");
const bodyParser = require("body-parser");
const express = require("express");
const path = require("path");
const api = require("./server/routes/api");
// create a new Express application instance
const app = express();
console.log( "dans server.js");
app.use(cors({origin:"*" })) ;
app.use(express.static('public'));
app.use(bodyParser.json());
console.log( "dans server.js");
//start application server on port 3000
server.listen(app.get('port'), function(){
console.info('Server listening on port ' + app.get('port'));
});
app.listen(3000, () => {
console.log("The server started on port 3000");
});
app.get("/",(req,res)=>{
res.send("");
});
app.post("/sendemail", (req, res) => {
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'emailsender@gmail.com',
pass: '*******'
}
});
var mailOptions = {
from: 'emailsender@gmail.com',
to: 'reciever@gmail.com',
subject: "hi with angular",
text: " hello great i sent u an email!"
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) console.log(error);
else console.log("Message sent successfully: " + info.response);
});
});
使用
发送邮件的代码contactform.ts:
router.post('/sendmail', actions.sendmail);
messageservice.ts
mysubmit(fo)
{console.log("submit");
this._MessageService.sendMessage (this.user) .subscribe (() => {
console.log(" service called submit");
console.log ("Contact form", "Message sent successfully", "success");
}}
错误消息:
HttpErrorResponse {headers:HttpHeaders,状态:0,statusText:“未知
错误”,网址:null,确定:false,...} 选项http://localhost:3000/sendmail net :: ERR_CONNECTION_REFUSED
may be the picture explains more the error
先谢谢您!