PHP Codes for Creating a BOT which will read your mails and send over IM

Chetan's Avatar

Chetan

06 Nov, 2009 04:57 AM via web

This will login to your Gmail account and get mails which are unread on IM screen.

http://pastebin.com/f339e5e51

  1. Support Staff 2 Posted by Adam Kalsey on 06 Nov, 2009 05:30 AM

    Adam Kalsey's Avatar

    Nice stuff. I'd suggest you put the gmail username and password in the
    script so you don't have to send it over IM. Instant messages aren't a
    terribly secure transport mechanism.

    To protect against random people accessing your inbox, put a check in
    for the userkey or the username and network, and only show the inbox
    if the message comes from the correct user.

  2. 3 Posted by Chetan on 06 Nov, 2009 05:32 AM

    Chetan's Avatar

    @Adam

    Thanks , yes I will update it .

  3. 4 Posted by mpahic on 06 Nov, 2009 01:59 PM

    mpahic's Avatar

    My bot does the same thing, it just uses the OAuth so it is more secure. The code is messy so, I won't post it when I make it more readable, but you can check my bot till then: ***@bot.im

  4. 5 Posted by Kiran on 15 Jan, 2010 07:42 AM

    Kiran's Avatar

    @Adam, @Chetan

    i tried the script but it is not working. replying bot connection field. :(

  5. Support Staff 6 Posted by Adam Kalsey on 15 Jan, 2010 03:44 PM

    Adam Kalsey's Avatar

    "Bot connection failed" indicates that our platform can't reach your
    web server. Check the url you have set in IMified. Also ensure that
    your web server is reachable over the public internet (isn't behind a
    firewall or on your home network).

  6. 7 Posted by kiran kumar on 15 Jan, 2010 05:50 PM

    kiran kumar's Avatar

    Hi Adam,

    Thanks alot for you response.
    I am sure that my web server is reachable over the public internet.
    There are few other scripts running successfully from the same web server.

    Even in this script it is asking for username/password in the first time,
    after giving the details it is showing "Bot connection failed" error.

    <?php
    if(!preg_match('/#inbox (.*):(.*)/',$_REQUEST['msg'],$logins))
    {
    echo "Use this commond to overview your inbox.[#inbox username:password]";
    }
    else
    {
    $username=$logins[1];
    $password=$logins[2];

    $url="https://$username:$***@mail.google.com/mail/feed/atom/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $result =curl_exec ($ch);
    curl_close($ch);
    $rss=$result;
    if(!preg_match('/Unauthorized/',$rss))
    {
    preg_match('/<fullcount>([0-9].*?)<\/fullcount>/',$rss,$fullcount);
    $fullcount=$fullcount[1];

    echo "{$fullcount} Unread Emails. \n \n\n";
    if($fullcount==0){exit;}

    preg_match_all('/<title>(.*)<\/title>/',$rss,$title);
    preg_match_all('/<summary>(.*)<\/summary>/',$rss,$summary);
    preg_match_all('/<issued>(.*)<\/issued>/',$rss,$issued);
    preg_match_all('/<name>(.*)<\/name>/',$rss,$name);
    preg_match_all('/<email>(.*)<\/email>/',$rss,$email);

    for($i=0;$i<=count($title[1])-2;$i++)
    {
    $nos=$i+1;
    echo "$nos";
    echo " :".$title[1][$i]."\n";
    }
    }
    else
    {
        echo "Unable to Login , Please Re-Try :)";
    }
    }
    ?>

    i have tried altering url to
    $url="https://".$username.":".$password."@gmail.google.com/gmail/feed/atom/
    ";

    Kindly assist me.
    Thank You

    Regards,
    Kiran B S

  7. Support Staff 8 Posted by Adam Kalsey on 15 Jan, 2010 06:46 PM

    Adam Kalsey's Avatar

    If your app were to return a 500 error or take a long time to respond,
    we would also return that message.

    What's your bot's Jabber name? I'll take a look at it.

  8. 9 Posted by kiran kumar on 15 Jan, 2010 06:52 PM

    kiran kumar's Avatar

    yes. it is taking long time to respond.
    My Jabber id is ****@bot.im*

  9. Support Staff 10 Posted by Adam Kalsey on 15 Jan, 2010 08:00 PM

    Adam Kalsey's Avatar

    You'll probably want to find a way to cache or pre-fetch the data that
    Google is sending. I just hit your URL directly with a username and
    password in there and it took 5 minutes 2.231 seconds to complete. Our
    timeout is much lower than that -- I believe it's currently configured
    at 30 seconds. If your app takes more than 30 seconds to respond,
    we'll assume it's unreachable and give up.

    One thing you could do is split the processing into two steps. First,
    reply instantly with something like "fetching your email, hang on a
    moment..." to tell the user you got their request. Then after you get
    the data from Google, use our send API to send a separate message to
    the user with their mailbox contents.

  10. 11 Posted by kiran kumar on 16 Jan, 2010 05:43 AM

    kiran kumar's Avatar

    Thanks alot Adam.
    Sure I will try doing that

    Regards,
    Kiran B S

  11. Adam Kalsey closed this discussion on 16 Jan, 2010 06:04 AM.

Comments are currently closed for this discussion. You can start a new one.