Skip to Content
Author's profile photo Former Member

ABAP POP3 Email Client Using an RFC enabled PHP client proxy

h3. Purpose  Recently a discussion  (calling php functions from sap) came up in the PHP Scripting forum on how to access an arbitrary POP3 mail server from within ABAP using any scripting language to build an RFC enabled POP3 client proxy but no webserver. I’ll present a prototype using PHP.   h3. Prerequisites   The examples shown here have been tested on ABAP WAS 6.40 and PHP 5.1 but they are very likely to run on much lower releases both on the ABAP and PHP side. The PHP side requires the SAPRFC libraries (SAPRFC  (http://saprfc.sourceforge.net/)) and it has to be compiled with imap support(in Windows enable php_imap.dll in php.ini).   h3. General   POP3 stands for Post Office Protocol version 3 and allows the retrieval of email from a server by a client application. The protocol is defined in RFC1939  (http://tools.ietf.org/html/1939). The second wide spread standard mail protocol is IMAP, the Internet Message Access Protocol, defined in RFC3501  (http://tools.ietf.org/html/3501).  PHP offers numerous functions to support this protocols. Those imap_* functions can be found here  (http://www.php.net/manual/en/ref.imap.php).    Although it’s quite simple to read a mailbox in principle it quickly gets difficult in a practical implementation. The protocols are very mature and stable but they support very complex email objects. An emai can consist of several parts, for instance a text body and several attachments. Each part can have a different mime type and subtype (e.g. TEXT/PLAIN, TEXT/HTML, IMAGE/GIF) and it can have it’s own encoding or character set(you probably know that unreadable mails due to ‘mixed’ character sets).   There is no defined order of this parts, so an attachment can come in front of or past the message body. This may lead to a situation, where a virus scanning program adds another TEXT/PLAIN part to the email, containing a note that the email has been scanned. Now, which one of two TEXT/PLAIN parts is the main message body? This is not defined.   Another problem arises from a fundamental conceptual difference between IMAP and POP3. IMAP is designed to support an online mail reading habit whereas POP3 is thought to be the offline mail management protocol. What does that that mean? With IMAP you download a temporary copy of an email to the client but the management of your account happens on the server. For instance, after downloading a mail you tell the server that you have  SEEN this mail. With POP3 on the other hand you download a mail to your client and ‘add it’ to your local permanent ‘mail store’. If you synchronize the next time you fetch an overview from the server, compare it with your local store and download only those you haven’t seen yet. That means, you need a local store and cannot flag the mail on the server. If you don’t have a local store (‘logbook’) you always have to download your whole mailbox.    In this blog I’ll show how to access an arbitrary mailbox by means of POP3 and PHP. The PHP programm will be designed to be a RFC server program which can be called from ABAP. So we finally have an ABAP POP3 mail client. Furthermore I’ll sketch out how to identify mime types (kinds of attachments) and how to store certain kinds of attachments(images of certain formats) to the filesystem.  h3. The PHP CLIENT PROXY  There are a lot of comments in the code so here I am going to explain the script in general only. We have to read it from bottom to top. A table type interface of data to be transferred is defined. We do not hand the complete unstructured mails to ABAP but selected structured data. This is +ORIGUID+,  an UID of the email, +MDATE+, the date the mail has been sent, +MTEXT+, the message body of the email, and finally +FINAME+, a unique filname for image type attachments. All fields are set to be abap type C.  A function +FETCH_EMAIL+ is registered and the server started.   The main function is +FETCH_EMAIL+. First some parameters have to be set, most notably an image directory for the attached images to be stored to, and the connection parameters to the mailbox. If we want to show attached images in an HTML control in our ABAP mail client we should set the image directory to a location on a webserver.$msgid));                     }                   }                 }               }             }           }           // uncommented the following to delete retrieved messages from the mail server           // $status = imap_setflag_full ($mbox, imap_uid($mbox,$msgno), ” DELETED”, ST_UID);         }       }     }     imap_close($mbox);   }   return (true); }  // the RFC interface, a table containing selected mail data $interface = array(                array(                  “name”=>”MAILTAB”,                  “type”=>”TABLE”,                  “optional”=>”0”,                  “def”=> array(                               array(“name”=>”MTEXT”, “abap”=>”C”, “len”=>”255”, “dec”=>0),                               array(“name”=>”FINAME”, “abap”=>”C”, “len”=>”32”, “dec”=>0),                               array(“name”=>”MDATE”, “abap”=>”C”, “len”=>”32”, “dec”=>0),                               array(“name”=>”ORIGUID”, “abap”=>”C”, “len”=>”32”, “dec”=>0)                             )                )              );  $rfc = saprfc_server_accept ($argv); saprfc_set_trace(0, true); $fcl[“FETCH_EMAILS”] = saprfc_function_define(0,”FETCH_EMAILS”,$interface);  while (true)   $rc = saprfc_server_dispatch ($rfc, $fcl);  ?>     h3. The ABAP CLIENT      REPORT ZTW_GET_EMAILS.  TYPES: begin of lst_mailtab,  mtext(255) type C,  finame(32) type C,  mdate(32) type C,  origuid(32) type C,  end of lst_mailtab. DATA: lt_mailtab type table of lst_mailtab,  ll_mailtab like line of lt_mailtab.   CALL FUNCTION ‘fetch_emails’ destination ‘PHPCONNECTOR’  TABLES MAILTAB = lt_mailtab.  loop at lt_mailtab into ll_mailtab.  write: / ll_mailtab-origuid, ll_mailtab-mdate, ll_mailtab-mtext,  ll_mailtab-finame.  endloop.     h3. Putting things together   First we define a RFC connection called PHPCONNECTOR in transaction SM59 as shown in the following image:  image    Next we change to the directory where we put our php script (e.g. C:usrsapNSPSYSexe
unphpstuff) and create our image directory in there. Now we are ready to run our PHP RFC mail client proxy with the following command     full/path/to/php-cgi.exe -dmax_execution_time=0 mailserver.php -a PHPCONNECTOR -g the_server -x sapgw00     where +-dmax_execution_time=0+ means ‘run forever’, +mailserver.php+ is the name of our script, +PHPCONNECTOR+ is our RFC destination defined earlier, +the_server+ is the name of the server, and +sapgw00+ the name of the SAP gateway.  The RFC connection can now be tested in SM59. If this test is okay we are ready to run our ABAP report. 
image

Assigned Tags

      19 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Hey Anton...What can I say...You're my new hero! -:D Your blog is just great and very easy to follow...This monday night I'm going to test it in my MiniSap System...Hope it works...

      Gotta try to implement some kind of mail reader...I don't have that much time, but it would be fun to try -;)

      Greetings,

      Blag.

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      glad you like it.
      maybe you're better in ABAP UIs than I am and we could enhance it with an appropriate UI and more functionality on the POP part.

      regars,
      anton

      Author's profile photo Gregor Wolf
      Gregor Wolf
      Hi Anton,

      you took a great thing together. With the win32service Functions you can also enable the PHP Server to run as a Service.

      Regards
      Gregor

      Author's profile photo Former Member
      Former Member
      hi Anton,
      I used your weblog to fix my problem but it shows me error in ABAP it was logged under the name " ".
      ( $mbox = imap_open($ServerName,$UserName,$PassWord, CL_EXPUNGE) )
      I have passed it the required parameters.
      $ServerName = "{192.168.1.35/pop3/notls:110}INBOX";
      $UserName = "ashishgarg@companyname.com";
      $PassWord = "xxxxxxxx";
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hi ashish,

      try to test the connection to the mailbox running the following script standalone:



      $ServerName = "{myserver.com/pop3/notls:110}INBOX";
      $UserName = "username+kwent.com";
      $PassWord = "xxxxxxxx";

      if($mbox = imap_open($ServerName, $UserName,$PassWord, CL_EXPUNGE)) {
      echo 'Successfully connected to mailbox';
      imap_close($mbox);
      }
      else { echo 'Connection failed with error: '. imap_last_error(); }


      ?>

      (run the script on the commandline with php-cgi.exe scriptname.php). The output should give you a hint on the error.
      Try to enter the username as ashishgarg+companyname.com.

      regards,
      anton

      Author's profile photo Former Member
      Former Member
      Hi Anton,
          I tried this code. I am getting this error.
      PHP Fatal error : call to undefined function imap_open( ).Anton actually our company does n't have our own mail server is this can be the reason of the error.
      regards
      ashish
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hi,

      call to undefined function imap_open() means just that. call to undefined function. you have to enable imap functions in php.ini in windows (uncomment extension=php_imap.dll
      ) and/or compile PH for unix with the "--with-imap" switch.

      You don't have to have your own mailserver. a request to port 110 has to be routed out of your network though.

      anton

      Author's profile photo Former Member
      Former Member
      hi Anton,
      I am able to to fetch mail content as date, mail text ,id but i am not geting attachement attachement file of the mail. How i will get that attachement
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hi there,

      I suppose you mean you don't get the attachment into ABAP.
      As you can see in the coding, I am saving the attachment to the filesystem after giving it a unique name but preserving the file extension (function write_to_fs).

      After that I am passing the filename of that file to ABAP via table MAILTAB, field FINAME. The connection to the main text body of the email is given by ORIGUID, which of course is the same for both.

      Mainly I did it that 'reference way' to avoid the discussion on how to handle streams of various file types and documents in ABAP.

      regards,
      anton

      Author's profile photo Former Member
      Former Member
      hi Anton,
      Below is code for attachement:-

      $new_fileName = write_to_fs($fileContent, $fileName, $imgDir);

      As u said I m using new_fileName as
                  "ATTACHEMENT"=>$new_fileName
      for finding attachement but i am not able to find that in ABAP ,can u give help through some  coding example.

      Thanks
      Gaurav

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hello,

      I am sorry, I do not understand what your problem is.
      - do you have a value for $new_filename but it is not transferred to ABAP? If you look at the last screenshot in the blog, you can see, that it is transferred in my example as c3b11f037...gif (and that's no fake screenshot)

      - do you ask me how to access the filesystem from within ABAP?

      What exactly do you want?

      If you want the binary stream of data in ABAP you just have to adopt the interface of your RFC module (to allow transferral of very long binary data) and then just pass it in the RFC. I just don't know what you like to do with a potentially arbitrary file attachment.  Actually I personally don't even know what to do with an even known filestream in ABAP, say a jpg or a zip. If I wanted to show an attached image on a dynpro, I'd move the image to a webserver's image path and reference it within a HTML control.

      anton

      Author's profile photo Former Member
      Former Member
      hi Anton,
      i want to read mail in ABAP with attachement , through your blog i am  reading  male text and saving in a data table  but not reading attachement.How i will read that attachement in ABAP.
      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hello,

      I already explained how you transfer the file stream.

      Say the attachment is a MS Word. How do you 'read' a MS Word file in ABAP? I don't know.

      Say the attached file is a WINZIP .zip file? How do you 'read' such a file in ABAP? I don't know.

      Say the attachment is NW2004sSP7_Preview_IDE.rar which is the latest Netweaver Developer Studio Installer. How do you 'read' such a file in ABAP? I don't know.

      If, and only if the content of your attachment is plain text in a suitable encoding you can directly 'read' it in ABAP when you have transferred it in the RFC interface.

      regards,
      anton

      Author's profile photo Former Member
      Former Member

      how to access the filesystem within ABAP and<br/><br/>how transfer the file stream to ABAP<br/><br/>Below is my code which is i am using same as your blog<br/><br/>saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                           "FINAME"=>$new_fileName,<br/>                                                          "MDATE"=>$date,<br/>                                                          "MTEXT"=>$msgBody,<br/>                                                        "SUBJECT"=>$subj ));<br/><br/>          //  get attachments if any<br/>          $struct = imap_fetchstructure($mbox,$msgno);<br/>          if (isset($struct->parts)) {<br/>            $structpart = $struct->parts;<br/>            $contentParts = count($struct->parts);<br/><br/>            if ($contentParts >= 2) {<br/>              for ($j=1;$j<=$contentParts;$j+) {<br/>                $att[$j-1] = imap_bodystruct($mbox,$msgno,$j);<br/>              }<br/>              for ($k=0;$k<sizeof($att);$k) {<br/>                if($att[$k]->type == 5){<br/>                  if ($att[$k]->parameters[0]->value == "us-ascii"<br/>                      || $att[$k]->parameters[0]->value == "US-ASCII") {<br/>                    //  accept only certain image types (Case sensitive!!)------<br/>                    if (ereg($attregexp, $att[$k]->dparameters[1]->value)<br/>                       || ereg($attregexp, 'x' . $structpart[$k]->subtype)) {<br/>                      $fileContent = imap_fetchbody($mbox,$msgno,$k1);<br/>                      $fileName = $att[$k]->dparameters[1]->value;<br/>                      // if filename is empty set it to a temporary using the mime subtype as fileext<br/>                      if ($fileName == "") { $fileName = "temp." . $structpart[$k]->subtype; }<br/>                      // write file to file system & record to db<br/>                      $new_fileName = write_to_fs($fileContent, $fileName, $imgDir);<br/>                   <br/>                     saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                                        "FINAME"=>$new_fileName,<br/>                                                                      "MDATE"=>$date,<br/>                                                                         "MTEXT"=>$msgBody,<br/>                                                                     "SUBJECT"=>$subj ));<br/><br/>                           <br/>                      <br/>;<br/>                    }<br/>                  }<br/>                  elseif ($att[$k]->parameters[0]->value != "iso-8859-1"<br/>                     &&    $att[$k]->parameters[0]->value != "ISO-8859-1") {<br/>                    // accept only certain image types (Case sensitive!!)------<br/>                    if (ereg($attregexp, $att[$k]->parameters[0]->value)<br/>                || ereg($attregexp, 'x' . $structpart[$k]->subtype)) {<br/>                      $fileContent = imap_fetchbody($mbox,$msgno,$k+1);<br/>                      $fileName      = $att[$k]->dparameters[0]->value;<br/>                      // if filename is empty set it to a temporary using the mime subtype as fileext<br/>                      if ($fileName == "") { $fileName = "temp." . $structpart[$k]->subtype; }<br/>                      // write file to file system & record to db<br/>                      $new_fileName = write_to_fs($fileContent, $fileName, $imgDir);<br/>   <br/><br/><br/><br/>           saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                                        "FINAME"=>$new_fileName,<br/>                                                                      "MDATE"=>$date,<br/>                                                                         "MTEXT"=>$msgBody,<br/>                                                                                      "SUBJECT"=>$subj ));<br/>                    }

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hello,

      I don't know how to access the filesystem from within ABAP.

      The transferral of the raw data to ABAP goes something like this:


      ...
      saprfc_table_append ($fce,"MAILTAB",array("MTEXT"=>"",
      "FILECONTENT"=>$fileContent,
      "MDATE"=>$date,
      "ORIGUID"=>$msgid));


      ...
      ...
      $interface = array(
      array(
      "name"=>"MAILTAB",
      "type"=>"TABLE",
      "optional"=>"0",
      "def"=> array(
      array("name"=>"MTEXT", "abap"=>"C", "len"=>"255", "dec"=>0),
      array("name"=>"FILECONTENT", "abap"=>"XXX", "len"=>"XXX", "dec"=>0),
      array("name"=>"MDATE", "abap"=>"C", "len"=>"32", "dec"=>0),
      array("name"=>"ORIGUID", "abap"=>"C", "len"=>"32", "dec"=>0)
      )
      )
      );

      for the interface parameter FILECONTENT you have to find a suitable(and RFC 'capable') BLOB data type), here denoted with XXX.

      anton

      Author's profile photo Former Member
      Former Member

      hi Anton,<br/>I m doing same but not able to read attachement in ABAP. i m sending my complet code plz check it and tell me where i m doing mistake.<br/><br/>Thanks<br/><br/><br/><br/><?php<br/><br/>function get_mime_type(&$structure) {<br/>  $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER");<br/>  if($structure->subtype) {<br/>    return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype;<br/>  }<br/>  return "TEXT/PLAIN";<br/>}<br/><br/>function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number    = false) {<br/>  if(!$structure) {<br/>    $structure = imap_fetchstructure($stream, $msg_number);<br/>  }<br/>  if($structure) {<br/>    if($mime_type == get_mime_type($structure)) {<br/>      if(!$part_number) {<br/>        $part_number = "1";<br/>      }<br/>      $text = imap_fetchbody($stream, $msg_number, $part_number);<br/>      if($structure->encoding == 3) {<br/>        return imap_base64($text);<br/>      } else if($structure->encoding == 4) {<br/>        return imap_qprint($text);<br/>      } else {<br/>        return $text;<br/>      }<br/>    }<br/><br/>    if($structure->type == 1) /* multipart / {<br/>      while(list($index, $sub_structure) = each($structure->parts)) {<br/>        $prefix = '';<br/>        if($part_number) {<br/>          $prefix = $part_number . '.';<br/>        }<br/>        $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix .    ($index + 1));<br/>        if($data) {<br/>          return $data;<br/>        }<br/>      }<br/>    }<br/>  }<br/>  return false;<br/>}<br/><br/>function write_to_fs($fileContent, $fileName, $imgDir) {<br/><br/>  //  create unique filename<br/>  $ext = explode(".", $fileName);<br/>  $nfn = substr(md5(uniqid(rand())),0, 15) . '.' . $ext[1];<br/>  //  save file to file system<br/>  $ih = fopen($imgDir . $nfn, "w");<br/>  $fileContent = base64_decode($fileContent);<br/>  fputs($ih, $fileContent, strlen($fileContent));<br/>  fclose($ih);<br/>  return $nfn;<br/>}<br/><br/>function fetch_emails($fce) {<br/><br/>  // define a directory where attached images are stored; php should have read and<br/>  // write access to it<br/>  $imgDir = "./imgs/";<br/><br/>  // POP3 data of the account where blogmails are sent to; 110 is the POP3 port number<br/>  // to change this to imap, see the php documentation for "imap_open(...)"<br/>  $ServerName = "{ko35/pop3/notls:110}INBOX";<br/>  $UserName = "gauravmehta@ko-india.com";<br/>  $PassWord = "xxxxxxxxxxxx";<br/><br/>  // define allowed attachment types; Case sensitive!!<br/>  // NOTE: if you define for example php here, someone can mail you a php-script and<br/>  // execute it; this may be very useful, but it may be extremly harmful too.<br/>  $atttypes = "jpeg|jpg|png|gif|JPG|JPEG|GIF";<br/><br/>  // some providers attach annoying footers; if they start with a certain string, we<br/>  // can strip them<br/>  $stripfoot = "--";<br/><br/>  saprfc_table_init ($fce,"MAILTAB");<br/><br/>  $attregexp = "(.(" . $atttypes . "))$";<br/><br/>//  if ( $mbox = imap_open($ServerName, $UserName,$PassWord, CL_EXPUNGE) ){<br/>       if ( $mbox = imap_open($ServerName, $UserName,$PassWord, CL_EXPUNGE) ){<br/>  //if ( $mbox = imap_open($ServerName, $UserName,$PassWord, CL_EXPUNGE) ){<br/>    if ($hdr = imap_check($mbox)) {<br/>      $msgCount = $hdr->Nmsgs;<br/>      if ($msgCount > 0) {<br/>        $MN=$msgCount;<br/>        $overview=imap_fetch_overview($mbox,"1:$MN",FT_UID);<br/><br/>        $size=sizeof($overview);<br/><br/>        for($i=0;$i<=$size-1;$i++){<br/>          $val=$overview[$i];<br/>          $msgno=$val->msgno;<br/>          $from=$val->from;<br/>          $date=$val->date;<br/>          $msgid =$val->message_id;<br/>            //$MANDT=$val->MANDT;<br/><br/>          $subj=$val->subject;<br/>          $subj1 = imap_mime_header_decode($subj);  //decode 8859 subject<br/>          $recent = $val->recent;<br/>          $flagged = $val->flagged;<br/>          $seen=$val->seen;<br/>          $from = ereg_replace("\"","",$from);<br/>          $uid = $val->uid;<br/>          //  get text body<br/>          $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");<br/>          $msgBody = ereg_replace("\n","<br>",$dataTxt);<br/>          $msgBody = ereg_replace("(<br>[^a-zA-Z0-9])$", '', $msgBody);<br/>          //  multiple <br>'s at the end into one<br/><br/>          // replace footers<br/>          if ($stripfoot != "") {<br/>            $msgBody = ereg_replace($stripfoot . ".*", '', $msgBody);<br/>          }<br/>          $msgBody = ereg_replace("'", "'", $msgBody); // replace single quotes<br/><br/>          //  enter the textpart into our mail table<br/>        <br/>          saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                           "FINAME"=>$subj,<br/>                                                          "MDATE"=>$date,<br/>                                                          "MTEXT"=>$msgBody,<br/>                                                        "ATTACHEMENT"=>"" ));<br/><br/>          //  get attachments if any<br/>          $struct = imap_fetchstructure($mbox,$msgno);<br/>          if (isset($struct->parts)) {<br/>            $structpart = $struct->parts;<br/>            $contentParts = count($struct->parts);<br/><br/>            if ($contentParts >= 2) {<br/>              for ($j=1;$j<=$contentParts;$j) {<br/>                $att[$j-1] = imap_bodystruct($mbox,$msgno,$j);<br/>              }<br/>              for ($k=0;$k<sizeof($att);$k) {<br/>                if($att[$k]->type == 5){<br/>                  if ($att[$k]->parameters[0]->value == "us-ascii"<br/>                      || $att[$k]->parameters[0]->value == "US-ASCII") {<br/>                    //  accept only certain image types (Case sensitive!!)------<br/>                    if (ereg($attregexp, $att[$k]->dparameters[1]->value)<br/>                       || ereg($attregexp, 'x' . $structpart[$k]->subtype)) {<br/>                      $fileContent = imap_fetchbody($mbox,$msgno,$k1);<br/>                      $fileName = $att[$k]->dparameters[1]->value;<br/>                      // if filename is empty set it to a temporary using the mime subtype as fileext<br/>                      if ($fileName == "") { $fileName = "temp." . $structpart[$k]->subtype; }<br/>                      // write file to file system & record to db<br/>                      $new_fileName = write_to_fs($fileContent, $fileName, $imgDir);<br/>                   <br/>                     saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                                        "FINAME"=>$subj,<br/>                                                                      "MDATE"=>$date,<br/>                                                                         "MTEXT"=>$msgBody,<br/>                                                                     "ATTACHEMENT"=>$fileContent ));<br/><br/>                           <br/>                      <br/>;<br/>                    }<br/>                  }<br/>                  elseif ($att[$k]->parameters[0]->value != "iso-8859-1"<br/>                     &&    $att[$k]->parameters[0]->value != "ISO-8859-1") {<br/>                    // accept only certain image types (Case sensitive!!)------<br/>                    if (ereg($attregexp, $att[$k]->parameters[0]->value)<br/>                || ereg($attregexp, 'x' . $structpart[$k]->subtype)) {<br/>                      $fileContent = imap_fetchbody($mbox,$msgno,$k+1);<br/>                      $fileName      = $att[$k]->dparameters[0]->value;<br/>                      // if filename is empty set it to a temporary using the mime subtype as fileext<br/>                      if ($fileName == "") { $fileName = "temp." . $structpart[$k]->subtype; }<br/>                      // write file to file system & record to db<br/>                      $new_fileName = write_to_fs($fileContent, $fileName, $imgDir);<br/>   <br/><br/><br/><br/>           saprfc_table_append ($fce,"MAILTAB",array( "ORIGUID"=>$msgid,<br/>                                                                        "FINAME"=>$subj,<br/>                                                                      "MDATE"=>$date,<br/>                                                                         "MTEXT"=>$msgBody,<br/>                                                                                      "ATTACHEMENT"=>$fileContent ));<br/>                    }<br/>                  }<br/>                }<br/>              }<br/>            }<br/>          }<br/>          // uncommented the following to delete retrieved messages from the mail server<br/>          // $status = imap_setflag_full ($mbox, imap_uid($mbox,$msgno), "
      DELETED", ST_UID);<br/>        }<br/>      }<br/>    }<br/>    imap_close($mbox);<br/>  }<br/>  return (true);<br/>}<br/><br/>// the RFC interface, a table containing selected mail data<br/>$interface = array(<br/>               array(<br/>                 "name"=>"MAILTAB",<br/>                 "type"=>"TABLE",<br/>                 "optional"=>"0",<br/>                 "def"=> array(<br/>                                  array("name"=>"ORIGUID", "abap"=>"C", "len"=>"32", "dec"=>0),<br/>                               array("name"=>"FINAME", "abap"=>"C", "len"=>"32", "dec"=>0),<br/>                             array("name"=>"MDATE", "abap"=>"C", "len"=>"32", "dec"=>0),<br/>                              // array("name"=>"MANDT", "abap"=>"C", "len"=>"3", "dec"=>0),<br/>                         //  array("name"=>"MSGFROM", "abap"=>"C", "len"=>"255", "dec"=>0),<br/>                        //   array("name"=>"MSGTO", "abap"=>"C", "len"=>"255", "dec"=>0),<br/>                        //  array("name"=>"MSGSUB", "abap"=>"C", "len"=>"255", "dec"=>0),<br/>                         array("name"=>"MTEXT", "abap"=>"C", "len"=>"255", "dec"=>0),<br/>                                array("name"=>"ATTACHEMENT", "abap"=>"C", "len"=>"255", "dec"=>0),<br/>                        <br/>                         <br/>                        <br/>                            <br/>                            <br/>)<br/>               )<br/>             );<br/><br/>$rfc = saprfc_server_accept ($argv);<br/>saprfc_set_trace(0, true);<br/>$fcl["FETCH_EMAILS"] = saprfc_function_define(0,"FETCH_EMAILS",$interface);<br/><br/>while (true)<br/>  $rc = saprfc_server_dispatch ($rfc, $fcl);<br/><br/>?><br/><br/><br/><br/><br/>ABAP report is:-<br/><br/>REPORT  ZPHP_TEST1.<br/><br/><br/>tables zmailtab1.<br/>DATA: lt_mailtab type table of zmailtab1,<br/>      ll_mailtab like line of lt_mailtab.<br/><br/><br/>CALL FUNCTION 'fetch_emails' destination 'PHPCONNECT1'<br/><br/>    TABLES MAILTAB = lt_mailtab.<br/><br/>loop at lt_mailtab into ll_mailtab.<br/><br/>write: / 'begin_of_mail', / ll_mailtab-origuid, / ll_mailtab-mdate,<br/>       / ll_mailtab-mtext,/ ll_mailtab-finame, / ll_mailtab-ATTACHEMENT,<br/>        / 'end_of_mail'.<br/><br/><br/><br/>INSERT INTO zmailtab1 values ll_mailtab .<br/><br/><br/>endloop.<br/><br/><br/><br/><br/><br/><br/>

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      hi there,

      what kind of attachment are you testing with?

      please send me a test email (the one we will both refer to in the following). for my email address see my BC.

      anton

      Author's profile photo Gaurab Banerji
      Gaurab Banerji

      excellent idea.. this innovation undoubtedly makes sap more flexible

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      wow,

      congratulations on first having been able to find this blog and second for having been able to read it. I hope I'll soon find time to re-format it and the experience of reading it will even be better 🙂

      kind regards, anton