试图弄清楚如何访问googles API,以便我可以在我的网站上创建联系表单,我找到了这个示例,但正在努力使用/转换为在Angular中使用。
https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/gmail/send.js
我刚做过npm install googleapis
,但不确定如何继续。我知道严格来说这不是编程问题,但我想知道是否有人可以帮助我为我的投资组合建立邮件(联系表格)。这也是我第一次使用API,并且我正在进行大量研究以弄清楚如何正确执行所有操作。
我正在尝试浏览google API上的文档,但是由于它是自动生成的,因此界面有点可疑... https://googleapis.dev/nodejs/googleapis/latest/index.html,我真的找不到关于它的任何有用信息。
我想做的是让人们与我联系的一种方式,因此我向工作地址发送了一封电子邮件,并附上了他们的邮件地址,以便我可以回复主题和正文。这就是我需要的所有信息,但是由于API尚不清楚,我很难弄清楚如何在Angular(Node.js)中做到这一点
TL; DR:如何将Angular 8(Node.js)连接到gmail api(或使用smtp)
更新:我改用nodemailer作为smtp了,但是它仍然无法正常工作
import * as mailer from 'nodemailer';
export class Mailing {
constructor() {
this.send();
}
async send() {
const account = await mailer.createTestAccount();
const transporter = mailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: account.user,
pass: account.pass
}
});
const info = await transporter.sendMail({
from: '"Portfolio" <Portfolio@gmail.com>',
to: 'torbenvanassche.dev@gmail.com',
subject: 'Hello',
text: 'shut up',
});
}
}
ERROR in ./node_modules/nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\sendmail-transport'
ERROR in ./node_modules/nodemailer/lib/mailer/index.js
Module not found: Error: Can't resolve 'dns' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\mailer'
ERROR in ./node_modules/nodemailer/lib/shared/index.js
Module not found: Error: Can't resolve 'dns' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\shared'
ERROR in ./node_modules/nodemailer/lib/dkim/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\dkim'
ERROR in ./node_modules/nodemailer/lib/mime-node/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\mime-node'
ERROR in ./node_modules/nodemailer/lib/shared/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\shared'
ERROR in ./node_modules/nodemailer/lib/mailer/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\mailer'
ERROR in ./node_modules/nodemailer/lib/shared/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\shared'
ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\smtp-connection'
ERROR in ./node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\smtp-connection'
ERROR in ./node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\smtp-connection'
ERROR in ./node_modules/nodemailer/lib/smtp-connection/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\tassc\Projects\Portfolio\node_modules\nodemailer\lib\smtp-connection'
更新:关于在Angular https://blog.angularindepth.com/google-apis-with-angular-214fadb8fbc5中使用google API的有趣文章
答案 0 :(得分:1)
您可以按照Node.js Gmail API quickstart设置可行的示例代码。然后,您可以使用sending mail tutorial对将邮件发送到您的帐户的功能进行编码。
在提供的链接中,您可以看到许多示例和详细步骤,但是如果您有任何疑问,请询问我。
编辑
在上一个快速入门链接上,我们所有人都可以看到当前建议的npm pakpage与Gmail API进行交互:npm install googleapis@39 --save
。您可以阅读有关Google库here的Node.js依赖项的更多信息。