Jump to content
Lape

smtp port 587 (or other than 25)

Recommended Posts

Lape    0

Hi guys - first - a warm thank you for making this plugin available, we have used Scriptmaster for 4 years now and have had NO problems until now - please advise:

The setup: FMS 13 on Windows 2008R2, ScriptMaster 4.1 and once a month a Email-blast with a few Emails/PDFs to recipients - no problems !

Now: we are relocating to another smtp-gateway, which only supports port 587....!   And THEN no more mails !

I have read/googled for days now, so i think I have tried the most common solutions, to no avail....

This is our code i SM-INIT-script and I THINK that its the "port" statement that is wrong:

---------cut------------

//Load ScriptMaster Functions

//HTMLEmail Function
RegisterGroovy (
"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);¶

props.setProperty (\"mail.smtp.port\", \"587\");¶

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

-------------------cut---------------------------------
 

The BOLD line is the new one - it was´nt in the code, so I assume it has to be inserted to work on other ports than default port 25....

I have tried to load NEW ScriptMaster (5.05) plugin, new activation.jar and mail.jar, but nothing helps...

The ScriptMaster 5.05 even halts FM Pro Advanced on serverconsole AND the server plugin (64 bits version) refuses to load for some reason - but THIS is not important - unless of course its going to be a part of the solution on this problem...

Anyone has a clue ??

Thank you in advance !

 

Lars G.

Share this post


Link to post
Share on other sites
Lape    0

Anyone ???

Share this post


Link to post
Share on other sites
john renfrew    30

Can you post the whole function and a list of the jars you are using...

 

first look props.setProperty (\"mail.smtp.port\", \"587\");¶

looks wrong - should be "mail.smtp.port", 587 - its a number not a string

Share this post


Link to post
Share on other sites
Lape    0

Hi John and thanks for replying - the quotes are in place because the whole text is... ehm... FileMaker-text and so the "´s is preceeded with a \, thus can I get values from variables as parameters....

The calculation - without the PORT-line - has been running PERFECT in 3-4 years - so I have to assume that the other code is OK !

The format you wrote - is that verified ??  I mean, do you know for sure its OK ??

 

Thanks again !

Oops sorry, forgot to show code:

Below is the complete INIT-code for the ScriptMaster-plugin - it works wonderfully, but i can´t figure out where to change the port...:

 

//Load ScriptMaster Functions

//HTMLEmail Function
RegisterGroovy (
"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);¶

props.setProperty (\"mail.smtp.port\", \"587\");¶

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;¶")

Share this post


Link to post
Share on other sites
john renfrew    30

Here is some code that works from G-Mail using port 587 and TLS

replace where obvious

Groovy code note: you dont need the ';' at the end of lines and in most cases you can use ' and not " as the string delimeiters, which makes it better to debug when in FileMaker

// gmailTest()
// v1.0
// 17_09_16
// J Renfrew
//

import javax.mail.Message
import javax.mail.MessagingException
import javax.mail.PasswordAuthentication
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
 
username = 'USERNAME@gmail.com'
password = 'PASSWORD'
 
props = new Properties()
	props.put('mail.smtp.auth', 'true')
	props.put('mail.smtp.starttls.enable', 'true')
	props.put('mail.smtp.host', 'smtp.gmail.com')
	props.put('mail.smtp.port', '587')
 
session = Session.getInstance(props,
	new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password)
		} //end authentication
	} //end authenticator
) //end session
 
try {
 
	message = new MimeMessage(session)
		message.setFrom(new InternetAddress('USERNAME@gmail.com'))
		message.setRecipients(Message.RecipientType.TO, InternetAddress.parse('EMAIL@MAIL.COM'))
		message.setSubject('Testing Subject')
		message.setText('Dear ScriptMaster,' + '\n\n No spam to my email, please!')
 
	Transport.send(message)
 
	return true
 
} catch (e) {
	return e.getMessage()
} //end try

 

You will need to work out how to make this send HTML and multipart HTML but that shouldn't be too hard.

This ALSO is confirmed to work with Office 365 on smtp.office365.com

 

Edited by john renfrew

Share this post


Link to post
Share on other sites
Lape    0

Ohh, GREAT John, thank you so much, I will try your code ASAP and return the result to you here...

 

Thanks again !

 

Kind regards, Gokke

Share this post


Link to post
Share on other sites

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


  • Who Viewed the Topic

    1 member has viewed this topic:
    VapanPagan 
×

Important Information

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