Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem with RegisterGroovy

Featured Replies

Hi.

I am very new to using plug ins so please forgive me if I am making a complete balls up of this. I am using SendEmailWith Authenitacation. This works great and I have to say is getting me out of a very big hole. The problems I am having is with registering this at start up. I have set a variable in the script I use at the start up of the database and inserted the code given. But it does not seem to work. If I use the Scripmasterfp7 to register it it works like a dream. Just to give you all the facts. I am giving the variable a name of $reg_plugin.

Can you paste the calculation you're using in your startup script?

  • Author

This is the calculation I am using in the variable directly as it is created by Scriptmaster:

RegisterGroovy( "SendEmailWithAuthentication( from ; to ; subject ; htmlBody ; attachmentPath ; smtpHost ; username ; password )" ; "import javax.mail.*;¶

import javax.mail.internet.*;¶

¶

Properties props = new Properties();¶

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

props.setProperty("mail.smtp.auth", "true");¶

props.setProperty("mail.smtps.auth", "true");¶

¶

¶

MimeMessage msg = new MimeMessage(Session.getDefaultInstance(props));¶

Multipart content = new MimeMultipart();¶

// first the message body¶

MimeBodyPart bodyPart = new MimeBodyPart();¶

bodyPart.setContent(htmlBody, "text/html");¶

content.addBodyPart(bodyPart);¶

// then the attachment¶

if (attachmentPath) {¶

	MimeBodyPart attachmentPart = new MimeBodyPart();¶

	attachmentPart.attachFile(attachmentPath);¶

	content.addBodyPart(attachmentPart);¶

}¶

msg.setContent(content);¶

msg.setSubject(subject);¶

msg.setFrom(new InternetAddress(from));¶

msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));¶

¶

Transport transport = Session.getDefaultInstance(props).getTransport("smtp");¶

int port = -1; // use the default port¶

transport.connect(smtpHost, port, username, password);¶

transport.sendMessage(msg, msg.getAllRecipients());¶

transport.close();¶

return true" )

What's happening is that the mail.jar and activation.jars are not being loaded. These two libraries are needed to send e-mail in Java, and they are included in the ScriptMaster development file. When you register the function, it registers the groovy code, but if the groovy code needs any 3rd party libraries to work, those need to be loaded as well.

To solve this, create 2 new container fields in a single-record table. Insert the mail.jar file into one container field, and activation.jar into the other container field (you can get these from the jar libraries table that comes with ScriptMaster). Then, just before you call RegisterGroovy, call SMLoadJar two times, one for each container field.

A more advanced technique, which is how we do it in the ScriptMaster file, is to create a table of jar files with one record per library. That way when you need more libraries, you just create new records instead of adding more container fields. If you do it this way, write a looping script that loops through the records and calls SMLoadJar on each one.

Edited by Guest

  • 1 month later...

Thanks, Jesse.

I was trying to do the exact same thing today, and encountered the same problems. Your explanation was just what I needed. Got it working. Thanks!!!

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.