August 24, 200817 yr 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.
August 25, 200817 yr 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" )
August 26, 200817 yr 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 August 26, 200817 yr by Guest
October 16, 200817 yr 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