在前端角度应用程序上访问gmail API

问题描述 投票:0回答:1

[试图弄清楚如何访问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)

更新:我更改为对SMTP使用nodemailer,但仍无法正常工作

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" <[email protected]>',
            to: '[email protected]',
            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 nodemailer
1个回答
0
投票

您可以按照Node.js Gmail API quickstart设置可行的示例代码。然后,您可以使用sending mail tutorial对将邮件发送到您的帐户的功能进行编码。

在提供的链接中,您可以看到许多示例和详细步骤,但是如果您有任何疑问,请要求我提供说明。

© www.soinside.com 2019 - 2024. All rights reserved.