douping5226 2019-02-18 19:40
浏览 345

如何从gmail API发送电子邮件

I have a script that get incoming emails to my gmail but now i also want to get emails that i send via email.

Here is the code that i have to get incoming emails

Please let me know what i need for outgoing emails as well

At the moment this code runs via pub sub on console.google.com

 $ch = curl_init('https://www.googleapis.com/gmail/v1/users/me/messages?labelIds=Label_56&maxResults=10');

    curl_setopt_array($ch, array(
        CURLOPT_POST => false,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer '. $tokenval,
             'Content-Type: application/json', 
        ),
    ));

    // execute request and get response
   $result = curl_exec($ch);


   $allmessages = json_decode($result);
   $allmessage = $allmessages->messages; 


   for($i=0;$i<count( $allmessage);$i++)
   {
       //echo $allmessage[$i]->id;
     $checkoldmsgid =  $this->Customer_m->getCount('messages',array('massageid'=>$allmessage[$i]->id ));

     if( $checkoldmsgid ==0)
     {

         $ch = curl_init('https://www.googleapis.com/gmail/v1/users/me/messages/'.$allmessage[$i]->id);

                curl_setopt_array($ch, array(
                    CURLOPT_POST => false,
                    CURLOPT_RETURNTRANSFER => TRUE,
                    CURLOPT_HTTPHEADER => array(
                        'Authorization: Bearer '. $tokenval,
                         'Content-Type: application/json'
                    ),
                ));

             // execute request and get response
            $resultm = curl_exec($ch);
            $msgval = json_decode($resultm);





            $sendernum =explode('@',$msgval->payload->headers[19]->value);
            $recivernum =explode('@',$msgval->payload->headers[0]->value);
            $createdat =   date('Y-m-d H:i:s',strtotime($msgval->payload->headers[18]->value));


             $massage = $msgval->snippet;


              $single_message = $service->users_messages->get("me", $allmessage[$i]->id);
              $payload = $single_message->getPayload();


            $body = $payload->getBody();
            $FOUND_BODY = $this->decodeBody($body['data']);
  • 写回答

1条回答 默认 最新

  • douchengchen7959 2019-02-19 02:54
    关注

    You'll probably want to use the SENT system label (instead of the Label_56 one) in your curl_init() call:

    SENT

    Applied automatically to messages that are sent with drafts.send or messages.send, inserted with messages.insert and the user's email in the From header, or sent by the user through the web interface.

    评论

报告相同问题?

悬赏问题

  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播