如何使用SMTP添加OAuth 2.0身份验证以使用JavaScript发送电子邮件?

发布于 2025-01-23 01:38:40 字数 1224 浏览 2 评论 0原文

我需要在现有的电子邮件提交表格中添加OAuth 2.0安全性。我在网上找到了其他一些方法,但是当我使用SMTP时,我只想添加必要的代码和令牌。但是不知道如何正确编码。

JavaScript

        function sendmail()

        {

        var name = $('#name').val();
        var email = $('#email').val();
        var subject = $('#subject').val();
        var message = $('#message').val();

        // var body = $('#body').val();

        var Body='name: '+name+'<br>email: '+email+'<br>subject: '+subject+'<br>message: '+message;
        //console.log(name, phone, email, message);

        Email.send({
            SecureToken : "",
            To : '',
            From : '',
            Subject: "New message on contact from "+name,
            Body: Body
        }).then(
            message =>{
                //console.log (message);
                if(message=='OK'){
                alert('E-mail has been sent successfully. Thank you ...');
                }
                else{
                    console.error (message);
                    alert('Error at sending message ...')
                    
                }

            }
        );

    }

当前只有此大量JavaScript代码使用SMTP协议发送电子邮件。但是Gmail正在禁用较低安全应用程序的访问。那么,我需要添加什么才能包括OAuth 2.0?

I need to add oauth 2.0 security in my existing email submission form. There are some other methods that I found online but as I am using smtp, I just want to add the necessary code and tokens. But don't know how to code it right.

JAVASCRIPT

        function sendmail()

        {

        var name = $('#name').val();
        var email = $('#email').val();
        var subject = $('#subject').val();
        var message = $('#message').val();

        // var body = $('#body').val();

        var Body='name: '+name+'<br>email: '+email+'<br>subject: '+subject+'<br>message: '+message;
        //console.log(name, phone, email, message);

        Email.send({
            SecureToken : "",
            To : '',
            From : '',
            Subject: "New message on contact from "+name,
            Body: Body
        }).then(
            message =>{
                //console.log (message);
                if(message=='OK'){
                alert('E-mail has been sent successfully. Thank you ...');
                }
                else{
                    console.error (message);
                    alert('Error at sending message ...')
                    
                }

            }
        );

    }

Currently only this much javascript code is sending email using smtp protocol. But gmail is disabling access for less secure app. So what do I need to add to include oauth 2.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文