Jump to content



Forward e-mail based on attachments


  • Please log in to reply
1 reply to this topic

#1 Fred Rogers  newbie

Fred Rogers
  • Newbies
  • PipPipPipPipPip
  • 5 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Beginner

Posted 26 January 2012 - 03:54 PM

Where to start.

We are now getting important client information e-mailed to us in the form of attachments.
The attachments have the clients name and a reference number in the file name. ie Smith, John, 1234567.pdf

What I would like is to forward the email message based on the attachment name, inducing the orignal attachment.

Or what would be even better if I could download the attachments, put them in a clients folder then e-mail the staff member alerting them that a clients files have been updated.

Right now I have a server script that runs every 15 minutes to get the mail.
I can see the attachment names, but I am unsure how to work with the files.


  • 0

#2 wbasham  apprentice

  • 360Works
  • 182 posts
  • Time Online: 4d 19h 47m 7s

Posted 27 January 2012 - 01:37 PM

Hello Fred,

This is not a trivial task to accomplish. There are many ways to approach this and I'll give you the one I think may be the simplest. You'll want to have the incoming messages stored in a table in the database. Then, you'd iterate through the messages and store everything you need in the table (ImportedMessage in this case).

Exit Loop If [not EmailGetNextMessage]
New Record/Request
Set Field[ImportedMessage::from ; EmailReadMessageValue( "from" )]
Set Field[ImportedMessage::to ; EmailReadMessageValue( "to" )]
Set Field[ImportedMessage::subject ; EmailReadMessageValue( "subject" )]
Set Field[ImportedMessage::body ; EmailReadMessageValue( "body" )]
Set Field[ImportedMessage::messageId ; EmailReadMessageValue( "messageId" )]
// OPTIONAL: mark this messages as "viewed"
// (You must pass readonly=false during EmailReadMessages to do this)
Set Variable[$result ; EmailMessageSetFlag("viewed")]
End Loop

You would add functionality to also store the file in a container field in the corresponding record. This could be accomplished by first passing in the optional flag "attachments=true" to the EmailReadMessages function. That will cause the files to be downloaded to a temp directory. You can then get the path of the attachment by calling EmailReadMessageValue( key ) with "key" being "attachments." Be careful here. This will return multiple lines of path names if there is more than one attachment. You'd probably also want to handle the cases where the emails either had no attachment, or not client attachments. This could be done with some clever scripting.

Once you have the path (still in the message iteration process) you can store the file in an "attachment" field in the ImportedMessage table mentioned above. You'd use the EmailReadAttachment( path ) with the result from EmailReadMessageValue above. At this point you'd have the associated attachment file in the same record as the message. If you are storing all messages in the table you may want to set a flag or something to differentiate between these specific kinds of emails.

From here you can do whatever else you need (send message with attachment, save files in client folder, etc.) in either the same server scheduled script (though I advise against it) or a different one for sending messages. In this script you could change another flag in the record based on a successful send of the email to avoid resending. You could also save the files to a unique client directory too.

I realize this may seem a bit complicated and depending on your level of experience it may be challenging. Keep in mind, we offer custom script development and are happy to offer you a quote. If you're interested in a quote please email me directly.
  • 0
Brent Basham

Also tagged with one or more of these keywords: attachments

FMForum Advertisers