Forum Moderators: coopster

Message Too Old, No Replies

Automate opening attachment from an email, run a script on it, & email

         

albert newton

3:54 am on Dec 2, 2008 (gmt 0)

10+ Year Member



There was a similar post earlier but I guess that was for Unix platform. I am using Windows XP, and need to do the following:

1.Automate opening an attachment from an email that I will be getting everyday.
2. Running a script (which I already have) on that attachment ( the attachment is going to be a .csv file).
3. Then after that script has run, that script will produce a different .csv file. I need to then automate running a script again on that file. ( I already have that script ready too).

4. The result of step 3 will be stored in a folder ( say under C:). I then need to automate the email distribution of that file to few people.

I know that I cannot use Cron for any of these purposes since I am using Windows. If someone can even help me with any number of steps above, I will be grateful.

vincevincevince

10:48 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have php's IMAP functions available?

albert newton

3:03 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



I do not have them yet, but I can surely download php and have them, if they are going to be used for my purpose... how are they going to fit into what I need to achieve?

vincevincevince

1:23 am on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP's IMAP functions will allow you to connect to a mailbox via IMAP, download new messages, and then parse out the attachments. [php.net...]

I had assumed you were planning on basing you script on PHP as this is the PHP forum?

albert newton

7:21 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Thanks for the information. I downloaded php, wrote a sample script to get(select) the email and its attachment. But when I try to run the script it gives me an error as follows:

C:\php-5.2.6-Win32>php.exe C:\emailattachmentscript.php

PHP Fatal error: Call to undefined function imap_open() in C:\emailattachmentscript.php on line 9

I uncommented the 'extension=php_imap.dll' line in the PHP.INI file, but it still did not get rid of the error.

I also pasted the php_image.dll file under the folders: C:\WINDOWS\system32 and C:\WINDOWS\system, but it still did not get rid of the error.

albert newton

9:05 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



I just figured that out, had to add dl("php_imap.dll"); at the top of the script ... now trying to figure out how to get the correct parameter in the imap_open function.

albert newton

10:25 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



I am unable to get the imap_open function to operate correctly in my script:

C:\php-5.2.6-Win32>php.exe -f C:\emailattachmentscript.php

PHP Warning: imap_open(): Couldn't open stream {EMAIL03.cerner.net}INBOX in C:\emailattachmentscript.php on line 17
Could not open Mailbox - try again later!PHP Notice: Unknown: Can't connect to EMAIL03.cerner.net,143: Refused (errflg=2) in Unknown on line 0

I tried searching online but cannot find the reason for this.

vincevincevince

1:06 am on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is email3.cerner.net running on port 143? Try:
telnet email3.cerner.net 143

albert newton

3:25 am on Dec 5, 2008 (gmt 0)

10+ Year Member



Here is what I get by running the above command:

C:\>telnet EMAIL03.cerner.net 143

Connecting To EMAIL03.cerner.net...Could not open connection to the host, on port 143: Connect failed

Here is the part of my script that is causing the headache...

$mbox = imap_open("{EMAIL03.cerner.net}INBOX", "albert_newton", "****") or die("Could not open Mailbox - try again later!");

( where **** is my network password to log into the system.)

I am using Microsoft Outlook 2003 and looking into the tools-> email accounts setting, I see that the Microsoft Exchange Server computer name is set as EMAIL03.cerner.net. Hopefully I have the right parameters for the imap_open function.

SarK0Y

8:35 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



Hi, albert newton.
where is mailserver placed(?): same machine with your script or other.

albert newton

8:41 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



Mailserver is placed on a different machine ( not on my machine, which has the script).

SarK0Y

9:46 pm on Dec 5, 2008 (gmt 0)

10+ Year Member



probably, fail's cause is firewall.

vincevincevince

3:45 am on Dec 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could not open connection to the host, on port 143: Connect failed

That's just the same error PHP will be seeing. SarK0Y is probably right - try disabling firewalls and retrying the telnet command. When telnet connects, PHP will be able to do so as well.

albert newton

10:40 pm on Dec 7, 2008 (gmt 0)

10+ Year Member



So the firewall problem is for the other machine (EMAIL03.cerner.net) right? I would need to disable the firewalls on that machine to allow access by my machine? Since I think removing the firewalls on my machine did not make any difference.

SarK0Y

11:29 pm on Dec 7, 2008 (gmt 0)

10+ Year Member



albert newton
try to load mail from another server then you will know workability your script/php.

albert newton

9:35 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



Ok, it looks like the telnet is not working for any mail server. I tried:

telnet pop.gmail.com 995
and also tried: telnet pop.mail.yahoo.com 110

But it still gives me the following error message:

Could not open connection to the host, on port --- : Connect failed

I tried adding exception for telnet and for those ports from the Windows Firewall program under control panel, but looks like this did not make any difference. Any ideas?

vincevincevince

12:22 am on Dec 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your ISP may well be blocking the ports (some do; but blocking incoming ports is fairly rare). Does any email client work for that PC?

Remember your router probably has its own firewall. Try, just for a minute, disabling this. If things start working, then you know you need to configure exceptions in there.