- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
最近怎么样?
我正在尝试弄清楚如何使用 Angular 5 和 Node.js - 使用 nodemailer- 发送电子邮件。
我想要存档的是当一些用户在页面中进行预约并且系统收到提供的电子邮件并在他们单击“安排我的......”按钮时向用户发送一些信息
正如您将在 appointment.component.ts 中看到的那样,当用户单击按钮时,变量会更改为“true”以向用户显示一些隐藏的 div 并显示一个 snackbar 但什么都没发生。控制台日志中没有错误,也没有任何错误。有什么想法吗?
下面是我的代码。提前致谢。
server.js
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const nodeMailer = require('nodemailer');
const api = require('./server/routes/api');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'dist')));
app.use('/api', api);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.post('/sendemail', (req, res) => {
let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'xxxxx@gmail.com',
pass: 'xxxxxxxxxxxxx'
}
});
let mailOptions = {
from: '"Nourish Team" <no-reply@nourish.io>',
to: "anyemailhere@gmail.com",
subject: 'Test',
text: 'Hello!',
html: '<b>Testing email function</b>'
};
transporter.sendMail(mailOptions, (error, info) => {
if(error) {
return console.log(error);
}
console.log('Message sent');
})
});
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`API running on localhost:${port}`));
appointment.component.html
<form novalidate action="/send-email" method="POST" (ngSubmit)="sendEmail()">
<mat-form-field class="middle-width" ngClass.xs="full-width">
<input matInput placeholder="Nombre Completo" [formControl]="fullName" required>
<mat-error *ngIf="fullName.hasError('pattern') && !fullName.hasError('required')">
El campo solo acepta letras.
</mat-error>
<mat-error *ngIf="fullName.hasError('required')">
¡Este cambo es <strong>requerido</strong>!
</mat-error>
</mat-form-field>
<mat-form-field class="middle-width" ngClass.xs="full-width">
<input matInput placeholder="Correo Electrónico" type="email" [formControl]="cEmail" required>
<mat-error *ngIf="cEmail.hasError('email') && !cEmail.hasError('required')">
Debes introducir un correo electrónico válido
</mat-error>
<mat-error *ngIf="cEmail.hasError('required')">
¡Este cambo es <strong>requerido</strong>!
</mat-error>
</mat-form-field>
<mat-form-field class="middle-width" ngClass.xs="full-width">
<input matInput placeholder="Teléfono" type="tel" [formControl]="phone" maxlength="14" mask="(000) 000 0000" required>
<mat-hint align="end">{{phone.value.length}} / 10</mat-hint>
<mat-error *ngIf="phone.hasError('pattern') && !phone.hasError('required')">
El campo sólo acepta números
</mat-error>
<mat-error *ngIf="phone.hasError('required')">
¡Este cambo es <strong>requerido</strong>!
</mat-error>
</mat-form-field>
<mat-form-field class="middle-width" ngClass.xs="full-width">
<input matInput [matDatepicker]="picker" placeholder="Elegir fecha">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker touchUi="true" #picker></mat-datepicker>
</mat-form-field>
<br>
<button mat-raised-button type="submit">Schedule My Appointment</button>
</form>
appointment.component.ts
sendEmail() {
this.sucess = true;
this.snackBar.open('Información enviada exitosamente.', 'x', {
duration: 5000,
});
this.name = this.fullName.value;
this.http.post('/sendemail', this.cEmail).subscribe(data => {
console.log(data);
});
}
I assume this code is to concatenated the node.js code into Angular5 app: this.http.post('/sendemail', this.cEmail).subscribe(data => {console.log(data);});
最佳答案
感谢您的代码!我的工作。也许您想更改您的 app.post 方法。
server.js
app.post("/sendemail", (req, res) => {
var transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
tls: {
chipers: "SSLv3"
},
auth: {
user: "xxx@hotmail.com",
pass: "xxx"
}
});
var mailOptions = {
from: "xxx@hotmail.com",
to: "xxx@gmail.com",
subject: "Nodejs Mail",
text: "this is the email's body text..."
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) console.log(error);
else console.log("Message sent successfully: " + info.response);
});
});
关于node.js - 使用 Angular 和 NodeMailer 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48605404/
我已经使用 sendInBlue 创建了一个帐户,并将 nodemailer 和 nodemailer-sendinblue-transport 导入到我的项目中,我正在尝试发送一封简单的确认电子邮件
我想使用客户端路由渲染我的 React 应用程序,并且我想使用 Nodemailer 发送邮件。由于 Nodemailer 不能在客户端使用,我必须在 Express 服务器上实现它。这是服务器的样子
我在让 nodemailer 与 AuthSMTP ( https://www.authsmtp.com/ ) 一起工作时遇到问题。 var nodemailer = require('nodemai
我是 nodejs 的新手,尝试从 nodemailer 模块发送邮件,但它有错误,即“不支持的配置,将 Nodemailer 降级到 v0.7.1 以使用它”。 这是我的代码:- var nodem
我正在使用 feathersjs 构建一个 API,我需要发送一封带有附件的电子邮件。 电子邮件似乎已发送,但我什么也没收到。 在我的 mail.service.js const nodemailer
我正在使用带有 mailgun 的 Nodemailer 向一组用户发送电子邮件。我正在生成 HTML 以使用 React 发送电子邮件。我想将电子邮件数组中的当前“收件人”传递给 React 组件,
我正在使用NodeMailer 。它运行良好,但我想发送一封匿名电子邮件(带有假姓名和电子邮件地址),但它不应该是这样。这是我的代码: let transporter = nodemailer.cre
我在 NodeMailer 中有这个代码用于发送电子邮件: var mailOptions = { from: 'test@test.com', to: 'send@send.com',
我正在将 nodemailer 与 npm 包电子邮件模板一起使用。我没有收到电子邮件。当我设置预览时模板正在工作:true。控制台出现错误错误:未定义收件人。为什么会出现此错误?尝试了很多方法,但
我遇到一个问题,如果我从定义了 Express 服务器的 app.js 调用我的订阅表单,它就可以完美工作,但如果我将 subscribe.js 移动到路由文件夹,我就无法发送邮件。我连接了两个文件,
我正在尝试使用nodemailer发送带有HTML表格的电子邮件。该表需要遍历数组。目前它的工作方式是为每次迭代发送一封单独的电子邮件,而不是发送带有表格的单个电子邮件。我尝试将 for 循环移至
我正在尝试使用 nodemailer 从我的 gmail 发送日历事件。 我使用 npm 包 ics 生成 ics 字符串。 const message = { from: '...',
我不太明白这一点...我有一个 SMTP 服务器与我托管在同一网络上,我可以 ping 它并尝试发送电子邮件,但实际的电子邮件从未通过。我正在使用 node_mailer ...在回调期间没有返回错误
我正在使用 nodemailer 发送邮件和附件。但是在发送附件之前我需要验证它是否存在,因此我将它分配给一个变量。但是当我使用变量时它不发送附件 working smtpTransport.send
{ [Error: Invalid login: 535 5.0.0 Authentication Failed] code: 'EAUTH', response: '535 5.0.0 Authen
我尝试使用nodemailer使用我的本地系统以及heroku应用程序发送邮件,但在这两种情况下我都超时,这是我的代码,现在我尝试使用gmail和smtp电子邮件,但仍然没有任何效果 exports.
我正在使用 Nodemailer 通过 Gmail 服务发送忘记密码的邮件。我尝试在 StackOverflow 中早期找到相同的错误,但找不到解决方案。请帮助我,我不知道为什么会出现这样的错误, "
发送电子邮件后尝试让我的页面从node.js 和express.js 页面重定向。消息已发送,我在终端中收到 console.log() (使用 morgan 进行日志记录),但它没有将我重定向到成功
我正在使用 nodemailer 从注册表单发送电子邮件。 这是我的表格 Registration
我使用 NodeMailer 和 Gmail API 从我的服务器发送电子邮件。当我在本地主机上测试它时,一切都很好。但是当我在我的服务器上运行它时,Nodemailer 没有任何响应,也没有发送任何
我是一名优秀的程序员,十分优秀!