Reactjs未调用Firebase函数nodeEmailer

Reactjs未调用Firebase函数nodeEmailer,reactjs,firebase,google-cloud-functions,Reactjs,Firebase,Google Cloud Functions,我已经在ReactJS中创建了一个联系人表单,并尝试使用firebase函数向自己发送电子邮件。电子邮件将包括该人在联系表中填写的内容 我使用postman尝试了firebase函数,它可以工作,当尝试端点时,我成功地收到了一封电子邮件 但是,当我尝试在我的React应用程序中调用它时,不会发送任何内容,也不会报告任何错误。我在网上查了一下,看我做错了什么,但运气不好 这是我的密码 firebase函数index.js // import needed modules const functio

我已经在ReactJS中创建了一个联系人表单,并尝试使用firebase函数向自己发送电子邮件。电子邮件将包括该人在联系表中填写的内容

我使用postman尝试了firebase函数,它可以工作,当尝试端点时,我成功地收到了一封电子邮件

但是,当我尝试在我的React应用程序中调用它时,不会发送任何内容,也不会报告任何错误。我在网上查了一下,看我做错了什么,但运气不好

这是我的密码

firebase函数
index.js

// import needed modules
const functions = require("firebase-functions");
const nodemailer = require("nodemailer");
const office365Email = functions.config().outlook365.email;
const office365Password = functions.config().outlook365.password;

// create and config transporter
const transporter = nodemailer.createTransport({
  host: "smtp.office365.com",
  port: 587,
  secure: false, // true for 465, false for other ports
  auth: {
    user: office365Email,
    pass: office365Password,
  },
});

// export the cloud function called `sendEmail`
exports.sendEmail = functions.https.onCall((data, context) => {

  // for testing purposes
  console.log(
      "from sendEmail function. The request object is:",
      JSON.stringify(data.body)
  );

    const email = data.email;
    const name = data.name;
    const message = data.message;


    // config the email message
    const mailOptions = {
      from: email,
      to: office365Email,
      subject: "New message from the nodemailer-form app",
      text: `${name} says: ${message}`,
    };


    return transporter.sendMail(mailOptions).then(() => {  
        return { success: true };
    }).catch(error => {
        console.log(error);
    });
});
以下是我的代码:

import React, {useRef, useState} from "react";
import {useAuth} from "../contexts/AuthContext";
import {useHistory} from "react-router-dom";
import firebase from 'firebase/app';
import classes from "./SyncManagerDemo.module.scss";
import {Button, Container, Form} from "react-bootstrap";


export default function ContactUs() {
    const nameRef = useRef();
    const emailRef = useRef();
    const messageRef = useRef();
    const firmRef = useRef();
    const history = useHistory();

    const [error, setError] = useState("")
    const [loading, setLoading] = useState(false)

    const sendEmail = firebase.functions().httpsCallable('sendEmail');

    async function handleSubmit(e) {
        e.preventDefault()
        
        console.log("nameRef: " + nameRef.current.value);
        console.log("emailRef: " + emailRef.current.value);
        console.log("messageRef: " + messageRef.current.value);

        return /*const test =*/ await sendEmail({
            name: nameRef.current.value,
            email: emailRef.current.value,
            message: messageRef.current.value
        }).then(result => {
            
            return console.log("message sent");
            
            }).catch(error => {  
          
                console.log("error occurred.");
                return console.log(error);            
        });

    }
    
    return (
        <React.Fragment>
            <div className={classes.body}>
                <Container>
                    <div className={classes.body}>
                        <h2>Contact Us</h2>                        
                        <Form onSubmit={handleSubmit}>
                            <Form.Group id="email">
                                <Form.Label>Email</Form.Label>
                                <Form.Control type="email" ref={emailRef} required/>
                            </Form.Group>
                            <Form.Group id="name">
                                <Form.Label>Name</Form.Label>
                                <Form.Control type="text" ref={nameRef} required/>
                            </Form.Group>
                            <Form.Group id="message">
                                <Form.Label>Message</Form.Label>
                                <Form.Control type="text" ref={messageRef} required/>
                            </Form.Group>

                            <Form.Group id="firm">
                                <Form.Label>Firm</Form.Label>
                                <Form.Control type="text" ref={firmRef} required/>
                            </Form.Group>                            
                            <Button disabled={loading} className="w-100" type="submit">
                                Send
                            </Button>
                        </Form>
                    </div>
                </Container>
            </div>
        </React.Fragment>
    )

感谢所有帮助。

日志中没有错误??没有。它在my
console.log(refs)
之后的末尾显示发送的
消息。您可以共享firebase初始化代码吗?我可以获取它。这与我使用的
电子邮件中的
有关。来自
电子邮件应该是我的Outlook 365电子邮件。firebase控制台中显示了一个错误,我错误地没有检查它。我相信发件人的电子邮件必须与您的配置电子邮件相匹配。因此,在本例中,显示
数据的最后一张图像应具有Outlook 365电子邮件。
的电子邮件可以更改为您想要的任何内容。
{
    "data": {
                "email": "my email@email.com",
                "name": "test name",
                "message": "hello world"
            }
}