Untitled
plain_text
a month ago
5.6 kB
4
Indexable
Never
public class MailTM { public string Email { set; get; } public string Password { set; get; } public string Domain { set; get; } public string Token { set; get; } public string html { set; get; } public List<string> ListIDMessenge { set; get; } private RestClient Client; private RestClientOptions options; private RestRequest request; public MailTM(string dom = "") { Setoptions(); Client = new RestSharp.RestClient(options); if (string.IsNullOrEmpty(dom)) GetDomain(); else Domain = dom; } private void Setoptions(string userAgent = "") { if (string.IsNullOrEmpty(userAgent)) userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"; if (options == null) options = new RestClientOptions() { CookieContainer = new System.Net.CookieContainer(), UserAgent = userAgent, Encoding = Encoding.UTF8, Expect100Continue = true, MaxRedirects = 100, FollowRedirects = true, ThrowOnAnyError = false, FailOnDeserializationError = false, ThrowOnDeserializationError = false, RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; }), PreAuthenticate = true }; } public void Login(string email, string pass, string action) { if (email.IsContains("@")) Email = email; else Email = email + "@" + Domain; Email = Email.ToLower(); Password = pass; string temp = ""; if (!action.Equals("Login")) { temp = Post("https://api.mail.tm/accounts", "{\"address\":\"" + Email + "\",\"password\":\"" + Password + "\"}").Result; //temp = temp.Replace("}", ",\"password\":\"" + Password + "\"}"); } temp = "{\"address\":\"" + Email + "\",\"password\":\"" + Password + "\"}"; string getTOken = Post("https://api.mail.tm/token", temp).Result; if (!string.IsNullOrEmpty(getTOken)) Token = Regex.Match(getTOken, "\"token\":\"(.*?)\"").Groups[1].Value; } public string GetMessenges() { if (string.IsNullOrEmpty(Token)) return "Lỗi login mail"; string temp = Get("https://api.mail.tm/messages").Result; if (string.IsNullOrEmpty(temp)) return "Lỗi request"; string idmail = Regex.Match(temp, "\"id\":\"(.*?)\"").Groups[1].Value; if (string.IsNullOrEmpty(idmail)) return ""; string getMes = Get("https://api.mail.tm/messages/" + idmail).Result; if (string.IsNullOrEmpty(getMes)) return "Lỗi request"; getMes = Regex.Unescape(getMes); string linkcode = Regex.Match(getMes.Replace("\\", ""), "fb[.]me/(.*?)\"").Groups[1].Value; return linkcode; } public void GetDomain() { int dem = 0; while (string.IsNullOrEmpty(Domain)) { dem++; if (dem > 5) break; string temp = Get("https://api.mail.tm/domains?page=1").Result; if (!string.IsNullOrEmpty(temp)) Domain = Regex.Match(temp, "\"domain\":\"(.*?)\"").Groups[1].Value; if (string.IsNullOrEmpty(Domain)) Task.Delay(3000).Wait(); } } public async Task<string> Post(string url, string data) { request = new RestRequest(url); request.AddHeader("accept", "application/json, text/plain, */*"); request.AddHeader("sec-fetch-site", "same-origin"); request.AddHeader("sec-fetch-dest", "empty"); request.AddHeader("accept-language", "en-US,en;q=0.9"); request.AddHeader("sec-fetch-mode", "cors"); request.AddHeader("referer", "https://mail.tm/"); request.AddHeader("sec-ch-ua-platform", "\"Windows\""); if (!string.IsNullOrEmpty(Token)) request.AddHeader("authorization", "Bearer " + Token); request.AddStringBody(data, "application/json"); request.Method = Method.Post; var res = await Client.ExecuteAsync(request); html = res?.Content; return html; } public async Task<string> Get(string url) { request = new RestRequest(url); request.AddHeader("accept", "application/json"); request.AddHeader("sec-fetch-site", "same-origin"); request.AddHeader("sec-fetch-dest", "empty"); request.AddHeader("accept-language", "en-US,en;q=0.9"); request.AddHeader("sec-fetch-mode", "cors"); request.AddHeader("referer", "https://mail.tm/"); request.AddHeader("sec-ch-ua-platform", "\"Windows\""); if (!string.IsNullOrEmpty(Token)) request.AddHeader("authorization", "Bearer " + Token); request.Method = Method.Get; var res = await Client.ExecuteAsync(request); html = res?.Content; return html; } ~MailTM() { try { Get("https://www.moakt.com/vi/inbox/logout").Wait(); } catch { } Client?.Dispose(); } }