Jump to content
Sign in to follow this  
Fred Rogers

Forward e-mail based on attachments

Recommended Posts

Fred Rogers    0

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.



Share this post

Link to post
Share on other sites
wbasham    2

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By martincl
      I see that I can download the attachment name with the IMAP connection.  Can I get the actual attachment file downloaded to a container?

    • By samarthmkt
      How we can send email with attachment while sending through 360 email plugin . Need any script for this. Thanks
    • By andru
      I'm working with a Go database and trying to email a pdf copy of a FM layout.

      I'm able to save the FM layout as a pdf without any problem and I'm able to then email a message from Go to an external email but I'm not able to get the saved pdf to attach to the email.

      I can see the saved pdf file in my files on the iPad and I can open it on my desktop, so I know that part worked.

      I'm suspecting that I haven't set the file path correctly in the attachment options. Any advice appreciated.
    • By rickyd
      Hi all,

      We just bought the 360works E-mail plugin, and we're having some trouble getting attachments to work properly. The script which is sending e-mails is supposed to pull attachments from a container field (Emails::attach1). And it does...sort of.

      The e-mail sends successfully, and contains an attachment. Except that the attachment is a .jpeg of what the container field LOOKS like, not a copy of the file it contains. I've tried this with .txt files, .zip files, .doc files, etc. Every time, I just get a picture of what the container field looks like.

      When sending documents, I get an image of the first page of the document.

      Any ideas what I'm doing wrong? Below is the line in the script that is doing the attachment. Platform is Windows 7 x64, Filemaker 10.3 Pro, E-mail plugin v. 1.96.

      Set Variable $emailattach = EmailAttachFile( Emails::attach1 )

      Any ideas?

      Thanks in advance.


Important Information

By using this site, you agree to our Terms of Use.