Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add canSend function to check mail sending capability #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tgloc
Copy link

@tgloc tgloc commented Apr 4, 2024

Description:

This pull request introduces a new function named canSend to the flutter_email_sender package. This function helps developers determine if the device is currently capable of sending emails.

Motivation:

On iOS devices, users need to have a default email app installed (e.g., Apple Mail) to send emails through the flutter_email_sender package. Without an email app, sending emails will fail. This new function provides a way to check compatibility before attempting to send an email, improving the user experience.

Implementation:

  • A new function named canSend() is added to the FlutterEmailSender class.
  • This function utilizes platform-specific checks to determine if a compatible email app is installed.
    • On iOS, it can potentially leverage a framework like MessageUI to check for available mail services.
    • On Android, the logic might involve checking for installed email apps or mail intent capabilities.
  • The function should return a bool value indicating whether the device can send emails.

Example Usage:

import 'package:flutter_email_sender/flutter_email_sender.dart';

Future<void> sendEmail() async {
  if (await FlutterEmailSender.canSend()) {
    // Proceed with email sending logic
    final email = Email(
      senderName: "Your Name",
      senderAddress: "[email protected]",
      recipients: ['[email protected]', '[email protected]'],
      subject: 'Your Email Subject',
      body: 'Your Email Body',
    );

    await email.send();
    
  } else {
    // Inform the user that email cannot be sent on this device
    print("This device cannot send emails. Please install an email app.");
  }
}

Feedback:

We welcome any feedback or suggestions on this pull request. Please feel free to leave comments or ask questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant