sidlatau / flutter_email_sender

Allows send emails from flutter using native platform functionality.
Apache License 2.0
146 stars 81 forks source link

Add canSend function to check mail sending capability #107

Open tgloc opened 3 months ago

tgloc commented 3 months ago

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:

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: "your_email@example.com",
      recipients: ['recipient1@example.com', 'recipient2@example.com'],
      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.