'Mail service working well but no email receiving

I created an email service with Mailgun api for django backend.

My view class is below;

view.py

class MyEmailView(View):
    def post(self, request, *args, **kwargs):
        
        data = json.loads(request.body)

        return requests.post(
            "https://api.mailgun.net/v3/mailgun.mydomain.com/messages",
            auth=("api", "*******-*****-****"),
            data={
                "from": data["from_email"],
                "to": data["to_email"],
                "subject": data["subject"],
                "text": data["message"],
                })

This is working well when I try it, I received the emails.

Also the sending function for frontend is below,

emailFunction.ts

export async function sendFunc(
  email: string,
  subject: string,
  message: string,
  setNotifMsg: any,
): Promise<any> {
  return fetch("https://myservisname.ondigitalocean.app/myendpoint", {
    method: "POST",
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      from_email: email,
      subject: subject,
      message: message,
      to_email: to_email,
    }),
  }).then((response: any) => {
    console.log("-> ", response)
    if (response.status === 200) {
      setNotifMsg("Your message has been sent!");
    } else {
      setNotifMsg("Error: Your message could not be sent");
    }
    return response;
  }).catch((error) => {
    console.error('Error:', error)});
}

The function is getting the inputs from the Form like below

Form.tsx

const sendMail = (values: any): void => {
    const { email, name, description } = values;
    const subject = "Message from: " + name + email;
    const message = "Message:\n" + description;
    sendFunc(email, subject, message, setResponseMessage);
  };

When I try to send an email via this form, the successful message appears and also I can see 200 status in the response in the console but I don't receive any email in my inbox.

What can be the problem?

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source