Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

VBScriptSendMail ( toAddress ; messageSubject ; messageBody ; attachment_path1 ; attachment_path2 ; attachment_path3 ; openOutlook )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.9  (72 votes)
  Discuss this Custom Function

Rodrigo Torres, Challenge Day
http://www.challengeday.org

For use on Windows - creates a VB Script that sends out an email with multiple (3) attachments.

Sample Input:
VBScriptSendMail ( brian@email.address , Test Email , Hi Brian! Check out these attachments. , C:\test1.txt , C:\test2.txt ,
C:\test3.txt , 0 )
Sample Output:
Option Explicit
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment (3)
Dim oFileObj
Dim ol
Dim olMailItem
Dim ns
Dim newMail
Dim myRecipient
Dim N
ToAddress = "brian@email.address"
MessageSubject = "Test Email"
MessageBody ="Hi Brian! Check out these attachments."
MessageAttachment (1) = "C:\test1.txt"
MessageAttachment (2) = "C:\test2.txt"
MessageAttachment (3) = "C:\test3.txt"
Set oFileObj = CreateObject("Scripting.FileSystemObject")
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem) newMail.Subject = MessageSubject newMail.Body = MessageBody &vbCrLf newMail.Recipients.Add(ToAddress)
N = 1
Do Until N > 3
If oFileObj.FileExists(MessageAttachment (N)) then newMail.Attachments.Add(MessageAttachment (N)) End If
N = N + 1
Loop
newmail.send
' Clean up
Set ToAddress = Nothing
Set MessageSubject = Nothing
Set MessageBody = Nothing
Set MessageAttachment (1) = Nothing
Set MessageAttachment (2) = Nothing
Set MessageAttachment (3) = Nothing
Set oFileObj = Nothing
Set ol = Nothing
Set olMailItem = Nothing
Set ns = Nothing
Set newMail = Nothing
Set myRecipient = Nothing


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

FileMaker's Send Mail script step is great until you need to send multiple attachments. FileMaker only allows one attachment. It is a limitation that has not been expanded yet.

This is a workaround for the PC Windows, using Outlook and VBScript (which will be run by Windows Script Host, at least it works for me on XP). See the comments at the top for details on the parameters and how to use it. I'm sharing this since it took me quite a while to put together and get it working, but it is provided "As is" and I make no guarantees.

Have fun!
===============
6/8/09 - Updated to handle multiple paragraphs in the message body. - RT
6/10/09 - Updated to warn user if file does not exist. -RT
12/15/11 - Minor comment changes to clarify. -RT

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 7 comments

Thanks for this. I'm working on something similar, and had come up with almost the same solution (setting a text field to contain my vbs code and exporting it with open, thereby running the vbs). Mine is tasked with navigating a POST website and the parameters are taken from a filemaker record's fields. So I have my vbs code all in the set field script step, concatenating the field values (parameters) with the code for dynamic POST searches.. My question is: is there any advantage to putting my vbs code into a custom function and passing parameters?

Now this might be getting too far off topic, but I'm seeking to retrieve info from the POST searches. My current approach is to have the vbs run the find and write the resulting url to a .txt, then import the .txt and parse within FM. Anyone have a better way? Is there a way to use the webviewer to navigate post websites? Thanks!

Ryan Thompson, Minneapolis
June 22, 2013 9:06am

I have no idea if anyone is monitoring this, but I wanted to say "thanks" and offer a tiny addition.

I wanted to put the recipeints in BCC instead of the TO field. I was able to, with a variation on Klaas's modification above.

Instead of: "newMail.To = ToAddress"
I used: "newMail.BCC = ToAddress"

It worked great!

THanks so much!

Jennifer Holland, Santa Barbara, CA
September 06, 2015 10:37pm

I get an email when anyone posts here and it's good to know this is still helping!
Thank you for posting and thank you especially for the addition!
-Rodrigo

Rodrigo Torres, Concord, CA
September 06, 2015 11:28pm

I have a question that reveals my lack of understanding of Visual Basic: is there any way to have this accept a variable numbers of attachments?

I tried creating a text variable in my script, and replacing the "MessageAttachment (1) = \"" & attachment_path1 & "\" lines with the name of the text variable, passing that text variable and the quantity of attachments. As you might guess, it didn't work. Basically, it would put the name of the variable into the script, not the contents.

Is there something easy and obvious that I'm missing? Or is does this need to be a fixed number of attachments? I guess I could create separate functions for 1 to 10 attachments, and call the correct one, but that seems laborious.

--Jennifer

Here's how it came out:

ToAddress = "jenninsb@gmail.com"
MessageSubject = "test multiple attachments"
MessageBody ="2 attachments"
attachment_paths

...and so on...

Jennifer Holland, Santa Barbara, CA
October 26, 2015 1:33pm

Hi Jennifer, Yes, this script can be changed to accept variable numbers of attachments. I know because that's how I have it implemented myself. My solution is to send an array to the custom function and then process that array so that the VB Script output has the right number of attachments for that particular email.

My solution, however, breaks up the processing into 3 separate custom functions that work together, and it's a little difficult to post those here since they don't work independently. Hmm... I'm open to any ideas on how best to share those. Thanks! Rorigo

Rodrigo Torres, Concord, CA
October 26, 2015 2:06pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 1 + 8 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions