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.

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 10 comments

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

Hi Rodrigo,
Thank you so match for your sharing. Great solution to workaround the FM limitation.
2 question:
1)How to avoid the message If you don't attach any attachment or you don't attach one of the 3 attachment?
2) How to add Bcc: and Cc: ?
Thank you for your sharing !!!
Appreciate
Shai

Shai, Modiin
January 20, 2018 9:06am

Hi Shai,
You are welcome!
1) Which message are you referring to?
2) This function doesn’t address cc or bcc. You can see Jennifer’s comment above on how she changed the function to accommodate cc.

Another way of making changes to an email (like adding cc or bcc) is to direct FM to open the email in Outlook before sending. In Send Mail, there’s an option for dialog on/off. If you set it to on then the email will open in Outlook (and not just send automatically) and at this point cc or bcc can be added. See https://www.filemaker.com/help/15/fmp/en/index.html#page/FMP_Help/send-mail .html

Of course at this point other attachments can also be added. This function is a way of adding additional attachments programmatically.

Rodrigo Torres, Concord, CA
January 20, 2018 10:01am

Hi Rodrigo,
Thank you so much for your prompt answer.
The message i refer belong to "The following file cannot be found and will not be attached:" when there is no attached at all or when do you attach only one attachment.

I'll follow Jennifer's comments.

Tank again !

Shai

Shai, Modiin
January 21, 2018 12:12am

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 4 + 5 =
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. HexUUIDToNum_cf (_uuid)
  (Sat, Jun 16, 1:55pm)
2. httpResponseCode ( responseHeaders )
  (Tue, Jun 12, 10:40pm)
3. FindDuplicateCharacters ( string )
  (Fri, Jun 08, 5:01pm)
4. FieldRepetitionLast ( field ; maxRepetition )
  (Wed, Jun 06, 6:05pm)
5. CountModifiedRecords ( NameTimestampField ; StartTimestamp ; EndTimestamp )
  (Mon, May 28, 8:23am)
6. JSONArrayLength ( JSONArrayStr )
  (Fri, May 25, 7:46am)
7. interpolation (y1; y2; y3; x1; x2; x3; x1y1; x2y1; x1y2; x2y2; rnd)
  (Sat, May 19, 3:55am)
8. @JSONFormatElements ( json )
  (Tue, May 15, 3:31am)

RSS Feed of Custom Functions