emailLog method

Future<void> emailLog({
  1. required String message,
  2. required String recipient,
  3. required String appTitle,
})

Sends a log message via email to the specified recipient.

The emailLog method sends an email containing the message to the specified recipient. It includes a subject indicating the application title and identifies the message as a custom error log.

  • message: The log message to be sent via email.
  • recipient: The recipient's email address.
  • appTitle: The title of the application, used as part of the email subject.

This method posts the log message to the specified server URL using an HTTP POST request. It includes necessary headers and JSON-encoded data. After sending the message, it checks the response status using _isStatusOk and logs the result.

Implementation

Future<void> emailLog(
    {required String message,
    required String recipient,
    required String appTitle}) async {
  final url = Uri.parse(CustomErrorConstants.SERVER_URL);

  var data = {
    'messages': {
      'recipient': recipient,
      'subject': '${CustomErrorConstants.CUSTOM_ERROR} - $appTitle',
      'message': message,
      'from': CustomErrorConstants.NO_REPLY_EMAIL,
      'replytoName': 'Custom Error',
      'fromName': 'no-reply',
      'replyto': CustomErrorConstants.NO_REPLY_EMAIL,
    },
  };

  final response = await http.post(
    url,
    headers: <String, String>{
      'Content-Type': 'application/json',
      'APIKEY': CustomErrorConstants.APP_API_KEY
    },
    body: jsonEncode(data),
  );

  _isStatusOk(response);
}