/send_email endpoint
This commit is contained in:
		
							parent
							
								
									5dc749eaec
								
							
						
					
					
						commit
						9d05e612cc
					
				
					 1 changed files with 45 additions and 2 deletions
				
			
		| 
						 | 
					@ -416,7 +416,11 @@ class ApiService {
 | 
				
			||||||
      if (mailsInSerializable.isEmpty) {
 | 
					      if (mailsInSerializable.isEmpty) {
 | 
				
			||||||
        return false;
 | 
					        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
 | 
					      //delete the email that is given to the
 | 
				
			||||||
      var url = Uri.http("$ip:$port", 'delete_email');
 | 
					      var url = Uri.http("$ip:$port", 'delete_email');
 | 
				
			||||||
| 
						 | 
					@ -437,4 +441,43 @@ class ApiService {
 | 
				
			||||||
      return false;
 | 
					      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