Hello all.
i can successfully jenerate mails, can see the amounts of message in the box. i can’T reach the link inside the mail. most likely i m not able to view the content as well. SO my code is below. Can You check it out please?
import requests
import json
import pyperclip
import re
def generate_email():
url = “https://gmailnator.p.rapidapi.com/generate-email”
payload = {"options": [3]}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "Your_Api_Key_Here",
"X-RapidAPI-Host": "gmailnator.p.rapidapi.com",
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
email = response.json()['email']
pyperclip.copy(email)
print(f"Generated email: {email}")
return email
def check_inbox(email):
url = “https://gmailnator.p.rapidapi.com/inbox”
payload = {"email": email, "limit": 10}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "Your_Api_Key_Here",
"X-RapidAPI-Host": "gmailnator.p.rapidapi.com",
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
return response.json()
def read_message(message_id):
url = “https://gmailnator.p.rapidapi.com/messageid”
params = {"id": message_id}
headers = {
"X-RapidAPI-Key": "Your_Api_Key_Here",
"X-RapidAPI-Host": "gmailnator.p.rapidapi.com",
}
response = requests.get(url, params=params, headers=headers)
message = response.json()
if 'body' not in message:
return {'subject': '', 'body': ''}
return message
def extract_links(message_body):
links = re.findall(‘https?😕/(?:[-\w.]|(?:%[\da-fA-F]{2}))+’, message_body)
return links
def delete_mail():
message_id = input("Enter the message ID of the email you want to delete: ")
if input("Are you sure you want to delete this email? (y/n): ").lower() == "y":
url = "https://gmailnator.p.rapidapi.com/delete"
payload = {"id": message_id}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "Your_Api_Key_Here",
"X-RapidAPI-Host": "gmailnator.p.rapidapi.com",
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.json())
if input("Do you want to restart the program? (y/n): ").lower() == "y":
main()
def main():
email = generate_email()
input_text = input("Type 'f' to proceed: ")
if input_text.lower() != "f":
return
inbox = check_inbox(email)
print(f"Number of emails in inbox: {len(inbox)}")
if len(inbox) > 0:
message_id = inbox[0]["id"]
message = read_message(message_id)
print(f"Message subject: {message['subject']}")
print(f"Message body: {message['body']}")
links = extract_links(message['body'])
if len(links) > 0:
print("Links found:")
for link in links:
print(link)
else:
print("No links found in the email.")
delete_mail()
if name == “main”:
main()
चर्चा में शामिल हों - नीचे टिप्पणी जोड़ें: