├── README.md └── tempmailbot.php /README.md: -------------------------------------------------------------------------------- 1 | # temporary-mail-bot 2 | 3 | Telegram @TemporaryMailBot source code 4 | 5 | Required PHP module: php-curl 6 | -------------------------------------------------------------------------------- /tempmailbot.php: -------------------------------------------------------------------------------- 1 | &$val) { 20 | if (is_array($val)) { 21 | $val = json_encode($val); 22 | } 23 | } 24 | $ch = curl_init('https://api.telegram.org/bot'.BOT_TOKEN.'/'.$method); 25 | curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); 26 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 27 | $result = curl_exec($ch); 28 | curl_close($ch); 29 | 30 | return $result; 31 | } 32 | 33 | function curl_get_contents($url) 34 | { 35 | $ch = curl_init($url); 36 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 37 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 38 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 39 | $result = curl_exec($ch); 40 | curl_close($ch); 41 | 42 | return $result; 43 | } 44 | 45 | function getMailDomains() 46 | { 47 | $mail_domains = curl_get_contents('https://getnada.com/api/v1/domains'); 48 | $mail_domains = json_decode($mail_domains, true); 49 | 50 | return $mail_domains; 51 | } 52 | 53 | function getInbox($address) 54 | { 55 | $inbox = curl_get_contents('https://getnada.com/api/v1/inboxes/'.$address); 56 | $inbox = json_decode($inbox, true); 57 | 58 | return $inbox; 59 | } 60 | 61 | function getMessage($id) 62 | { 63 | $message = curl_get_contents('https://getnada.com/api/v1/messages/'.$id); 64 | $message = json_decode($message, true); 65 | 66 | return $message; 67 | } 68 | 69 | function generateRandomString($length = 5) 70 | { 71 | $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; 72 | $characters_length = strlen($characters); 73 | $randomString = ''; 74 | for ($i = 0; $i < $length; $i++) { 75 | $randomString .= $characters[rand(0, $characters_length - 1)]; 76 | } 77 | 78 | return $randomString; 79 | } 80 | 81 | $update = file_get_contents('php://input'); 82 | 83 | if (!empty($update)) { 84 | $update = json_decode($update, true); 85 | if (isset($update['message'])) { 86 | $message = $update['message']; 87 | $chat_id = $message['chat']['id']; 88 | $first_name = $message['from']['first_name']; 89 | if (isset($message['text'])) { 90 | $text = mb_strtolower($message['text']); 91 | if ($text == '/start') { 92 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'Hi, '.$first_name."! Press NEW ADDRESS to get new temporary e-mail address.\n\nBy @Radio_Nima", 'reply_markup' => ['keyboard' => [[['text' => 'NEW ADDRESS']]], 'resize_keyboard' => true]]); 93 | } elseif ($text == 'new address') { 94 | $mail_domains = getMailDomains(); 95 | $mail_address = generateRandomString(rand(5, 6)).'@'.$mail_domains[array_rand($mail_domains)]['name']; 96 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'E-Mail: '.$mail_address, 'reply_markup' => ['inline_keyboard' => [[['text' => '📩 Inbox', 'callback_data' => $mail_address]]]]]); 97 | } elseif (filter_var($text, FILTER_VALIDATE_EMAIL)) { 98 | if (preg_match('/^([a-zA-Z0-9\._]+[A-Za-z0-9_])@(.*?)$/u', $text, $mail)) { 99 | $mail_domains = getMailDomains(); 100 | if (in_array($mail[2], $mail_domains)) { 101 | $mail_address = $mail[1].'@'.$mail[2]; 102 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'E-Mail: '.$mail_address, 'reply_markup' => ['inline_keyboard' => [[['text' => '📩 Inbox', 'callback_data' => $mail_address]]]]]); 103 | } 104 | } else { 105 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'This address has been expired.', 'reply_markup' => ['keyboard' => [[['text' => 'NEW ADDRESS']]], 'resize_keyboard' => true]]); 106 | } 107 | } else { 108 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'Hi, '.$first_name."! Press NEW ADDRESS to get new temporary e-mail address.\n\nBy @Radio_Nima", 'reply_markup' => ['keyboard' => [[['text' => 'NEW ADDRESS']]], 'resize_keyboard' => true]]); 109 | } 110 | } 111 | } elseif (isset($update['callback_query'])) { 112 | $callback_query = $update['callback_query']; 113 | $callback_query_id = $callback_query['id']; 114 | $callback_data = $callback_query['data']; 115 | $chat_id = $callback_query['from']['id']; 116 | $inbox = getInbox($callback_data); 117 | $inbox = $inbox['msgs']; 118 | if (!empty($inbox)) { 119 | teleRequest('answerCallbackQuery', ['callback_query_id' => $callback_query_id]); 120 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => 'Inbox of '.$callback_data.':']); 121 | foreach ($inbox as $message) { 122 | $message_content = getMessage($message['uid']); 123 | $message_text = 'From: '.$message['f']."\nAt: ".$message['rf']."\nContent:\n".$message_content['text']; 124 | teleRequest('sendMessage', ['chat_id' => $chat_id, 'text' => $message_text]); 125 | } 126 | } else { 127 | teleRequest('answerCallbackQuery', ['callback_query_id' => $callback_query_id, 'text' => 'No letters in '.$callback_data]); 128 | } 129 | } 130 | } 131 | --------------------------------------------------------------------------------