Cornel
Cornel

Reputation: 79

Why do I not receive the email from flutter app?

I recently published my first app on Play Store and I have a problem. I made a thing where the player can send a feedback via email so I can see it. When I tested it with my emulator, it worked, and I got all the emails I've sent. But now, from a user's phone, it doesn't work and I do not know how to fix that. I am using the EmailJS service.

Future<void> sendEmailSentence() async {
    const serviceId = 'service_4wejtie';
    const templateId = 'template_c0g3vmb';
    const userId = 'z2swDcLIPp9H0pa6e';

    final url = Uri.parse('https://api.emailjs.com/api/v1.0/email/send');
    final response = await http.post(
      url,
      headers: {
        'origin': 'http://localhost',
        'Content-Type': 'application/json',
      },
      body: json.encode({
        'service_id': serviceId,
        'template_id': templateId,
        'user_id': userId,
        'template_params': {
          'user_name': myControllerName.text,
          'user_message': myControllerSentence.text,
        }
      }),
    );
  }

This is the piece of code that I am using. I repeat, from the emulator, from my laptop...it is working. But from someone else's device, it does not.

Upvotes: 0

Views: 273

Answers (2)

Yusuf Ansari
Yusuf Ansari

Reputation: 46

EmailJS account page By default API calls are disabled for non-browser applications You need to activate API requests through Account Security, you'd find a checkbox there to enable this feature.

Upvotes: 0

raj kavadia
raj kavadia

Reputation: 1053

Can you try removing the code for headers

 headers: {
    'origin': 'http://localhost',
    'Content-Type': 'application/json',
  }

This shows origin is the localhost which might not be running inside the physical device. It might be running inside your system where your server is running but not be working in device/ firewall issues.

Upvotes: 1

Related Questions