/send_email endpoint
This commit is contained in:
		
							parent
							
								
									5dc749eaec
								
							
						
					
					
						commit
						9d05e612cc
					
				
					 1 changed files with 45 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -411,12 +411,16 @@ class ApiService {
 | 
			
		|||
    // post
 | 
			
		||||
    try {
 | 
			
		||||
      List<SerializableMessage> mailsInSerializable =
 | 
			
		||||
        await this.threadsInSerializable(thread_id.toString());
 | 
			
		||||
          await this.threadsInSerializable(thread_id.toString());
 | 
			
		||||
 | 
			
		||||
      if (mailsInSerializable.isEmpty) {
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
      Map<String, String> requestBody = {"from": from_folder, "uid": mailsInSerializable.first.uid.toString(), "to": "not used"};
 | 
			
		||||
      Map<String, String> 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<bool> sendEmail(
 | 
			
		||||
      String? to, String? subject, String? emailContent) async {
 | 
			
		||||
    try {
 | 
			
		||||
      var url = Uri.http('$ip:$port', 'send_email');
 | 
			
		||||
 | 
			
		||||
      Map<String, dynamic> 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;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue