From 9d05e612cccad2575490fa9f11553f78ad0a1a8f Mon Sep 17 00:00:00 2001 From: juan Date: Wed, 20 Aug 2025 17:42:57 -0400 Subject: [PATCH] /send_email endpoint --- lib/api_service.dart | 47 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/api_service.dart b/lib/api_service.dart index f40f93d..4b7a087 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -411,12 +411,16 @@ class ApiService { // post try { List mailsInSerializable = - await this.threadsInSerializable(thread_id.toString()); + await this.threadsInSerializable(thread_id.toString()); if (mailsInSerializable.isEmpty) { return false; } - Map requestBody = {"from": from_folder, "uid": mailsInSerializable.first.uid.toString(), "to": "not used"}; + Map requestBody = { + "from": from_folder, + "uid": mailsInSerializable.first.uid.toString(), + "to": "not used" + }; //delete the email that is given to the var url = Uri.http("$ip:$port", 'delete_email'); @@ -437,4 +441,43 @@ class ApiService { return false; } } + + Future sendEmail( + String? to, String? subject, String? emailContent) async { + try { + var url = Uri.http('$ip:$port', 'send_email'); + + Map requestBody = { + "to": [to ?? ""], + "cc": [], + "bcc": [], + "subject": subject ?? "Untitled", + "in_reply_to": "", + "messages": [ + { + "message": emailContent ?? "", + "is_html": false}], + "attachments": [], + "inline_images": [], + }; + var response = await http.post( + url, + headers: { + 'Content-Type': 'application/json', + }, + body: jsonEncode(requestBody), + ); + if (response.statusCode == 200) { + print("response body: ${response.body}"); + } else { + print('error: ${response.statusCode}, response body: ${response.body}'); + return false; + } + + return true; + } catch (e) { + print("error in post send email $e"); + return false; + } + } }