DropMail

פרמיום
על ידי seriyps | מְעוּדכָּן hace 24 días | Email
פּוֹפּוּלָרִיוּת

9 / 10

חֶבִיוֹן

105ms

רמת שירות

100%

Health Check

N/A

חזרה לכל ההדרכות (2)

How to create new temporary mail address and read incoming email with cURL

Intro

In this tutorial we are going to create a new temporary mailbox, receive an email and read it. All by accessing DropMail 10 minute mail API using cURL command-line HTTP utility.

Step 1: Get API access key

Choose the appropriate free or paid plan on the “Pricing” page https://rapidapi.com/seriyps/api/dropmail/pricing and
then use your regualr RapidAPI access key to access the API.

Here we store the API key as $RAPIDAPI_KEY shell variable:

$ export RAPIDAPI_KEY=e9da83f1c5...d50

Step 2: Start a new session with temporary email address

Here we are asking DropMail.me to start a new “session” with new random email address connected to it and asking it to return session ID (it will be used later to read the incoming mail) and email address

$ curl --request POST \
	--url https://dropmail.p.rapidapi.com/ \
	--header 'content-type: application/json' \
	--header 'x-rapidapi-host: dropmail.p.rapidapi.com' \
	--header "x-rapidapi-key: $RAPIDAPI_KEY" \
	--data '{"query":"mutation { introduceSession { id, expiresAt, addresses { address }}}"}'

{"data":{"introduceSession":{"id":"U2Vzc2lvbjpeKYsIk9NJ9TiHzV8Gu","expiresAt":"2021-03-23T23:30:50+00:00","addresses":[{"address":"example@dropmail.me"}]}}}

Here

  • U2Vzc2lvbjpeKYsIk9NJ9TiHzV8Gu is the sesion ID
  • example@dropmail.me is the temporary email that is ready to receive new mail
  • "expiresAt":"2021-03-23T23:30:50+00:00" means that this session will self-destruct at that time in the future (so, it will delete all the received mails and addresses and disappear), unless it will be accessed via API.

Step 3: Send the email

Now you can try to send an email to example@dropmail.me from your personal email or try to register on some website using this temporary mail address.

Step 4: Read the mail

When you think that email should be already delivered, use session query to read all the mail received by your session:

$ curl --request POST \ 
    --url https://dropmail.p.rapidapi.com/ \
    --header 'content-type: application/json' \
    --header 'x-rapidapi-host: dropmail.p.rapidapi.com' \
    --header "x-rapidapi-key: $RAPIDAPI_KEY" \
    --data '{"query":"query checkSession($id : ID!) {session(id: $id) {mails{rawSize,fromAddr,toAddr,downloadUrl,text,headerSubject}}}","variables":{"id":"U2Vzc2lvbjpeKYsIk9NJ9TiHzV8Gu"}}'

{"data":{"session":{"mails":[{"toAddr":"example@dropmail.me","text":"Hello world!\r\n","rawSize":2339,"headerSubject":"Test","fromAddr":"test@example.com","downloadUrl":"https://dropmail.me/download/mail/gql:123456:dcbb4c8e-14c0-4568-b405-41e86e294539/qgiqg35mf8llheqm18l7u0fnvvs1vdhb"}]}}}

As you see, data.session.mails is the array of all the mails received by this session. We add "variables":{"id":"U2Vzc2lvbjpeKYsIk9NJ9TiHzV8Gu"} to the request JSON to tell which session to check for incoming mail. And we ask the server, for each email it received, to return the size of the raw email - rawSize, address from which the mail was sent - fromAddr, temporary address to which the email was sent - toAddr (because the session can have multiple addresses attached to it), URL where the whole raw email in MIME format can be downloaded (size of this file will be equal to rawSize) - downloadUrl and email’s plain text content and subject - text and headerSubject.

Try more advanced techniques

There are many more Mail fields available (such as attachments, address alias, HTML version of the email and so on). Also, there are other than Session.mails field ways of accessing the emails received by the session, which are useful when you are receiving many emails with the same session (pagination). So, check the DropMail GraphQL API schema and detailed DropMail 10 minute mail API documentation to learn more!