VBScriptSendMail ( toAddress ; messageSubject ; messageBody ; attachment_path1 ; attachment_path2 ; attachment_path3 ; openOutlook )
Rate this function: Average rating: 3.9 (72 votes)
Discuss this Custom Function
Rodrigo Torres, Challenge Day
For use on Windows - creates a VB Script that sends out an email with multiple (3) attachments.
|VBScriptSendMail ( email@example.com , Test Email , Hi Brian! Check out these attachments. , C:\test1.txt , C:\test2.txt ,
C:\test3.txt , 0 )
Dim MessageAttachment (3)
ToAddress = "firstname.lastname@example.org"
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
' 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
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.
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
5 most recent comments | Show all 10 comments
Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:
Newest Custom Functions:
||(Sat, Jun 16, 1:55pm)
||httpResponseCode ( responseHeaders )
||(Tue, Jun 12, 10:40pm)
||FindDuplicateCharacters ( string )
||(Fri, Jun 08, 5:01pm)
||FieldRepetitionLast ( field ; maxRepetition )
||(Wed, Jun 06, 6:05pm)
||CountModifiedRecords ( NameTimestampField ; StartTimestamp ; EndTimestamp )
||(Mon, May 28, 8:23am)
||JSONArrayLength ( JSONArrayStr )
||(Fri, May 25, 7:46am)
||interpolation (y1; y2; y3; x1; x2; x3; x1y1; x2y1; x1y2; x2y2; rnd)
||(Sat, May 19, 3:55am)
||@JSONFormatElements ( json )
||(Tue, May 15, 3:31am)