Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 2955 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I am a bit of a noob with ScriptMaster/Groovy, but managed to patch together different scripts I found to produce a flexible HTML Email script.

I thought it might be useful to the ScriptMaster Community so am sharing it here. Any feedback/suggestions appreciated.

It supports multiple attachments, and multiple recipients (separated by semicolons). Currently it only supports HTML (not plain text) as I only needed HTML.

The code is as follows:

HTMLEmail ( from ; to ; cc ; bcc ; subject ; htmlbody ; attachmentPath ; smtpHost )

import javax.mail.*;

import javax.mail.internet.*;



Properties props = new Properties();

props.setProperty("mail.smtp.host", smtpHost);

MimeMessage msg = new MimeMessage(Session.getInstance(props));



if (attachmentPath == null) {

  // HTML E-Mail Only



  msg.setContent(htmlbody, "text/html");

}

else {

  // HTML E-Mail with Attachment(s)



  Multipart content = new MimeMultipart();



  // first the message body

  MimeBodyPart bodyPart = new MimeBodyPart();

  bodyPart.setContent(htmlbody, "text/html");

  content.addBodyPart(bodyPart);



  // then the attachment(s)

  attachmentPath.tokenize(";").each {it ->

    attachmentPart = new MimeBodyPart();

    attachmentPart.attachFile it;

    content.addBodyPart attachmentPart;

  }



  msg.setContent(content);

}



msg.setSubject(subject);

msg.setFrom(new InternetAddress(from));



to.tokenize(";").each {it ->

  msg.addRecipients(Message.RecipientType.TO, new InternetAddress(it))

}

if (cc != null){

  cc.tokenize(";").each {it ->

    msg.addRecipients(Message.RecipientType.CC, new InternetAddress(it))

  }

}

if (bcc != null){

  bcc.tokenize(";").each {it ->

    msg.addRecipients(Message.RecipientType.BCC, new InternetAddress(it))

  }

}



Transport.send(msg);

return true;




The other thing I noticed is that it's tricky to have a neat solution to register ScriptMaster functions. I found it a bit over the top to have to open ScriptMaster.fp7 on startup.

Therefore I use the following simple script instead:



Register ScriptMaster


#Registers ScriptMaster Functions

#

#Check Extension is installed

If [ SMVersion = "?" or SMVersion < 4 ]

Show Custom Dialog [ Title: "Error"; Message: "Could not load ScriptMaster Extension."; Buttons: “OK” ]

End If

#

#Load Activation.jar and Mail.jar

Set Variable [ $result;

Value:

//Load External Modules

SMLoadJar ( SendHTML::Activation.jar ) and SMLoadJar ( SendHTML::Mail.jar )

]

If [ $result = "ERROR" ]

Show Custom Dialog [ Title: "Error"; Message: "Could not load external modules."; Buttons: “OK” ]

End If

#

#Register Functions

Set Variable [ $result; Value://Load ScriptMaster Functions - see example file ]

If [ $result = "ERROR" ]

Show Custom Dialog [ Title: "Error"; Message: "Could not load external functions"; Buttons: “OK” ]

End If

I have put together an example database which is attached.

Hope this is useful.

SendHTML.zip

  • Like 2
Posted

I recommend registering scriptmaster modules in your startup script as well, rather than loading the scriptmaster.fp7 file with your solution each time. To help with this we have three options for registering modules when you click "register this function" on your scriptmaster module. The third option you are presented with after clicking that button is the "paste into your solution" option, with a button to copy the scriptmaster code to the clipboard. Once you've done that all you need to do is paste the code into a set variable script step, which will insert the registergroovy function you would need to do the registration in a set variable script step in your startup script.

Posted

Thanks for that info Smef - I wasn't aware of that functionality.

However although this creates the RegisterGroovy function (and looks pretty handy) it does not generate the rest of the script such as checking that ScriptMaster is installed, registering the required JAR files, or any error checking.

Posted

Thanks for this contribution jaboda. I have seen a few posts asking how to add more than one attachment, so I think this will be useful.

Others can take note of the method jaboda used to send more than one attachment path as a single function parameter. That is another common request.

  • 1 month later...
  • Newbies
Posted

Is it just me or have you noticed that each TO CC and BCC address must be unique or the duped email addresses doesn't get sent?

Posted

Is it just me or have you noticed that each TO CC and BCC address must be unique or the duped email addresses doesn't get sent?

I haven't tested it, but I imagine it should work.

  • 3 years later...
  • Newbies
Posted

Can anyone by chance send me the files attached to this thread. The link seems to not be working.

 

My email is mcmillin.josh (at sign) yahoo (dot) com

 

Thanks

  • 1 year later...
Posted

I have now updated this script to allow for authentication (for use with Google's SMTP Servers, but should work with others).

You can see the new version here.

This topic is 2955 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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