Jump to content

Commanline Email Attachment Download


CoyoteRed

Recommended Posts

I'm looking to automatically download PQ's and run a batch file on them. I have all of the components except for the ability to download and extract the attachments.

 

Anyone know of MS commandline program to open a POP3 account, download the email, extract the attachments, and place them in a directory? Preferrably one that can return an error code for branching on results.

 

Much appreciated.

Link to comment

What I'd like to do is just call of batch file with a scheduler let the batch file run, do it's thing and then close. It's fairly simple to do once the attachment is in the directory. It's got to run locally because it involves GPXspinner and custom templates.

 

I understand GPXspinner is a perl program wrapped in a DOS executable. If a perl program can be written and wrapped, that would work. I just need to pass the server, account, password, and target directory. It should return an error code if there was no work done to stop the batch. Beyond that, I'd just setup the PQ to go to a special mailbox so I don't have to worry about anything else getting processed.

 

This program need not be used only for what I want it for. It could be used to automate PQs in general. I'd probably even use it to automate the download of my other PQs, run GPXspinner and then Plucker so everything would be ready Saturday morning when I get up. (I run a Friday and a Saturday PQ for fall-back and redundancy.)

 

Anyone up to the challenge?

Link to comment

It's probably overkill, and it depends on your skill level, but there's always fetchmail (windows/cygwin version here - note that you'll need the appropriate cygwin DLL and some other DLLs; you might want to look around for a mingw version instead) for retrieving the mail from your mailbox and uudeview (windows console version here) to decode the attachments.

 

Note, though, that Fetchmail will just download everything in your mailbox, so unless you have a dedicated mailbox just for PQs and such, it's probably not what you want. In a pinch, you can specify the -k option to make it leave mail on the server, but then you'll download your (probably huge) PQ results again when you check your mail with your usual mail client.

 

The option you want for Fetchmail to write its output to a file is --bsmtp. There'll be some excess cruft in the file, and any line starting with a . will have the . doubled, and all of the messages will be in one big file, but none of those should affect uudeview's ability to decode the attachments.

Edited by parkrrrr
Link to comment

Well, I found a program even better than Popget. It's called GetMail. It can download and decode your mail for you.

 

What I was trying to accomplish is keep our local GC club's first page up to date on the caches placed in the last 7 days. The listings will simply link back to gc.com.

 

While I don't have it actually on the site at this very momment, the script is working beautifully.

 

What is does:

- checks a special mailbox I set up for just this PQ.

- If there is mail, it downloads it and then deletes it off the server.

- It checks to see if there is a ZIP file. If not it cleans up and ends.

- If there is a ZIP, it deletes the message body and extracted text leaving the ZIP

- It calls GPXspinner and spinner creates a simple listing.

- It then deletes the ZIP files as they are no longer needed.

- It then calls FTP and uploads the list and then quits.

 

INAP but here it is: (Please don't laugh!)

   @echo off
  e:
  cd..
  cd pqgpx
  getmail -pw 123456 -xtract -delete
  if not ERRORLEVEL == 0 goto Error
  if exist *.zip goto gotone
  echo
  echo No GPX to process!  Quiting...
  echo
  goto cleanup
  
  :Error
  echo Error!
  goto end
  
  :gotone
  echo We got one!  Running GPXspinner....
  echo
  C:\Progra~1\GPXSpi~1\GPXSpi~1.exe -i=7day.ini
  if exist *.txt del *.txt
  if exist *.zip del *.zip
  if exist *.out del *.out

  cd cache
  ren index_~1.htm 7day.txt
  ftp -s:../7day.scr ftp.iscga.org 
  goto end

  :cleanup
  if exist *.txt del *.txt
  if exist *.out del *.out

  :end

 

Works great and as soon as I layout how I want the list to be presented I'll do a simple #include.

 

I plan on doing something similar for my regular caching PQs. Another mailbox and a different script that will also call Plucker and I'm set!

 

Thanks for the help everyone!

Edited by CoyoteRed
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...