Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email from exchange server into MySQL database 1

Status
Not open for further replies.

DrDan1

Technical User
Oct 2, 2002
127
0
0
GB
I need to have any emails sent to a particular email address to get placed into a table in a MySQL database. I know it's a simple matter to have this done using a web form, but this case requires email.

I've noticed something about this in the threads using the impa function but the emails are via an exchange server. Can the same process still be used, as I believe Exchange uses MAPI??

I'm using PHP5.2.8 on Apache 2.2 in a windows environment. Is anyone out there able to help or offer some guidance? I'm well and truly stuck.

----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!
 
Hmm... I'm getting somewhere. I've decided to run this as a script rather than via apache. The script will update the database with email properties, such as body and subject. That I can do ok now.

But of course I don't want it to do the same messages all the time, so I'd like it to move the messages to a subfolder once they have been processed, using the move method (VBA).

I'm still new to working with objects and I can't quite get this to work. Basically how would I move an email from one subfolder to another? Let's say I created 2 subfolders in the inbox called 'movedfrom' and 'movedto' to work with.

----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!
 
There is a move method on the mailitem object you could use the EnytryID property which is unique to each mailitem. You could use that as a key in the db?.
I casn have a look for you but it'll be a few days as I'm up to my neck in it at the momment !
 
Thanks. I'm really grateful for what you've shown me so far. If you get a chance if a few more days that'd be great. :)

I can get the script to move the email from and to default folders. i.e. From '5' for sent items to '6' for inbox. (I had some fun when I got those mixed by accident).

Below is my code that works between default folders. I reach difficulties when I try and do it from and to custom folders that I have created in Outlook.

Code:
  <?php

		//$sentItemsFolder = 5;
		$realMessage = 43;

		$outlook = new COM("outlook.application");

		$mapi = $outlook->getnamespace("mapi");
		//$mapi->logon("drobertson","password");
		//$sentFolder = $mapi->getdefaultfolder($sentItemsFolder);
		$fromSentFolder = $mapi->getdefaultfolder(5);
		$toInboxFolder = $mapi->getdefaultfolder(6);
		$items = $fromSentFolder->items;
		
		echo "you have " . $items->count . " items";
		
		foreach ($items as $ite)
		{
		  if ($ite->class == $realMessage)
		    echo 'Subject: ' . $ite->subject . "\n";
		  	echo 'To: ' . $ite->to . "\n";
		    echo 'From: ' . $ite->sendername ."\n";
		    echo 'Sender\'s email: ' . $ite->senderemailaddress ."\n";
		    $ite->move($toInboxFolder);
		  	echo '-----------------------------------------' . "\n";
			
		}
  ?>

----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!
 
I THINK I DID IT!!!! :-D
I got it to move an email from the sent box to a sub folder of the sentbox called 'moved'

Thanks again. couldn't have got this far without your help.

Code:
  <?php

		//$sentItemsFolder = 5;
		$realMessage = 43;

		$outlook = new COM("outlook.application");

		$mapi = $outlook->getnamespace("mapi");

		$fromSentFolder = $mapi->getdefaultfolder(5);
		$toMovedFolder = $fromSentFolder->Folders("moved");

		$items = $fromSentFolder->items;
		
		echo "you have " . $items->count . " items";
		
		foreach ($items as $ite)
		{
		  if ($ite->class == $realMessage)
		    echo 'Subject: ' . $ite->subject . "\n";
		  	echo 'To: ' . $ite->to . "\n";
		    echo 'From: ' . $ite->sendername ."\n";
		    echo 'Sender\'s email: ' . $ite->senderemailaddress ."\n";
		    $ite->move($toMovedFolder);
		  	echo '-----------------------------------------' . "\n";
			
		}
  ?>

----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!
 
@ingresman

i get countless emails each day where people include a corporate logo within their sig. i suppose i could call it equally an 'inline attachment'.

additionally, when I was at t-mobile our exchange implementation meant that we were forever getting annoying ATT00001.txt type attachments, which were plain text alternatives to the message body. when i wrote an exchange->mysql converter that handled attachments i found it 'annoying' to have to add so many exceptions within the looping of the attachments collection to filter out the unwanted attachments, and for the inlines i was only able to differentiate based on file size, which was far from ideal. i also half-wrote a hash comparison so that i would not have to store inline/non-inline images individually for each email but could compare hashes and decide whether to link to a pre-stored image. Nice idea, but i was running a 0.9GHz mobile pentium at the time, and the performance was treacle-like. T-Mobile was exceptional though, the quantity of email was well in excess of 400 non-spam per day and i was full of ideas to create decent searching of mail boxes. (not to mention the 1/2GB, then 1GB then 2GB limitation on mail box and pst sizes) then along came google desktop and is shelved the project (another one consigned to the dust cart!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top