Premise [download] Module: SSMTP - Send email using SSL.

Motorola Premise

123

Senior Member
File Name: Module: SSMTP - Send email using SSL.
File Submitter: 123
File Submitted: 15 May 2010
File Category: Premise
Author: 123
Contact: PM me
Version: 1.3

SSMTP is a driver that provides a convenient means to send email via Secure SMTP. It offers the following conveniences:

Secure SMTP
SSMTP relies on Collaborative Data Objects (CDO) in order to send email using Secure Socketsw Layer (SSL). In addition, SSMTP supports authentication which, together with SSL, ia required if you wish to send email via Google's Gmail service.

Centralized device
The SSMTP is a custom device driver so it resides in Devices > CustomDevices > SSMTP. Let's say you've preconfigured it to send email, via Gmail (smtp.gmail.com), to your phone. If you ever need to change the destination or carrier, you don't need to modify every script that sends email, you simply change it in the SSMTP device.

Default values
SSMTP can be preconfigured with default values. For example, it can be configured to send email via your Gmail account to you and your spouse. As a result, email scripts are simplified because you only need to specify a Subject and Body. Other properties such as From, To, MailServer, Account, Password, etc are all predefined by you. Here's a sample email script that relies on a preconfigured SSMTP device:
Code:
with Device.CustomDevices.SSMTP
	.Subject = "Warning: Garage Door left open."
	.MailHTMLBody = "Garage door left open:" & now
	.MailSend = true
end with

Auto-reset
Your script can override a default value and specify a unique one. After the email is sent, the default values are automatically restored. For example, the following script overrides MailTo's default value. After the message is processed, MailTo will be restored to its default value.
Code:
with Device.CustomDevices.SSMTP
	.Subject = "Warning: Garage Door left open."
	.MailTo = "[email protected], [email protected]"
	.MailHTMLBody = "Garage door left open:" & now
	.MailSend = true
end with

MailLog
SSMTP keeps a record of the last five email messages. The message's Status property will indicate the transmission time or, if a problem was encountered, the cause of the failure.

Installation
Using Builder, import the attached XDO file.

Configuration
  1. In the Shortcut bar, click Modules.
  2. In the Explorer window, navigate to Modules > SSMTP > Classes > SSMTP
  3. Click the MailFrom property.
  4. In the Properties window, locate and set MailFrom's default value.
  5. Repeat this procedure for MailTo.
  6. In the Explorer window, navigate to Modules > SSMTP > Classes > SSMTPConfiguration
  7. Click the SMTPServer property.
  8. In the Properties window, locate and set SMTPServer's default value.
  9. Repeat this procedure for all other SMTP properties.
  10. In the Shortcut bar, click Devices.
  11. In the Explorer window, right-click Devices > CustomDevices and select New > SSMTP. An SSMTP device will appear in the list containing properties with the default values you've chosen.

Usage
Here's a script fragment that emails CallerID information.
Code:
			with Devices.CustomDevices.SSMTP
				.MailSubject = "Telephone call: " & this.CallerIDName & ", " & this.CallerIDNumber
				.MailHTMLBody = "<b>Name:&nbsp;</b>" & this.CallerIDName & "<br>" & _
								"<b>Number:&nbsp;</b>" & this.CallerIDNumber & "<br>"  & _
								"<b>Time:&nbsp;</b>" & this.CallerIDDateTime & "<br>"  & _
								"<b>CallsAway:&nbsp;</b>" & this.CallsAway & "<br>" 
				.MailSend = true
			end with

Notes
  • The fully-qualified email format is (for multiple recipients): "John" <[email protected]>, "Mary" <[email protected]>
  • The simplest email format is (for multiple recipients): [email protected], [email protected]
  • Email messages typically contain content in two forms, in HTML and in text-only. It is preferable to use the MailHTMLBody property instead of MailTextBody. The driver will automatically strip the HTML tags from MailHTMLBody and use that to populate the MailTextBody property. If you do use MailTextBody, the driver will simply copy its contents to MailHTMLBody (without HTML tags).

Click here to download this file
 
Microsoft Office365's SMTP servers use SSL, but on a different port (587). You don't support setting the SSL port.

I looked at the code and changed:


if this.SMTPUseSSL then​
.Item (sPath & "smtpserverport") = 465​

to


if this.SMTPUseSSL then​
.Item (sPath & "smtpserverport") = 587​

I still get 'The transport failed to connect to the server.'

I've verified that my setup is working correctly by using a gmail address (and port 465).

Any suggestions?
 
Ok, regarding this problem:

Turns out Office365 requires you to use port 25 when doing TLS over SSL.

I changed this module as follows:

I added a new property to SSMTP.Classes.SSMPTConfiguration:
SMTPSSLPort - Integer, default value 465

I changed SendMail:


if this.SMTPUseSSL then
.Item (sPath & "smtpserverport") = this.SMTPSSLPort
.Item (sPath & "smtpusessl") = True
else
.Item (sPath & "smtpserverport") = 25
.Item (sPath & "smtpusessl") = False
end if

Then for MY configuration I set SMTPSSLPort to 25 and it works.

Cheers!
 
It appears this TLS hack no longer works. CDO does not support TLS. I was able to get SSTMP working again by installing https://smtpproxy.codeplex.com/ and using it as a proxy. I configured SSMTP to NOT use SSL and the server of smtp.office365.com and now it is all working.
 
I have started using Gmail as my SMTP proxy. Even after adding Charlie's changes (above), I was getting either locked out or security errors from Gmail.
It turns out Premise (c. 2000) is considered "Unsafe". However, after some searching, I now have 123's SSMTP working. Again.
 
To use Gmail as an SMTP proxy:
   1) Either use your Gmail account ID or create one if you want to identify where the email is coming from (I added a .Premise, so I know    which house its coming from)
   2) Login to your account (or the one you just created), and select "Account", then "Security"
   3) Scroll down to "Signing In To Google"
   4) Enable Two Step Verification (You'll now have to go thru some verification steps; just follow the instructions)
   5) Once Two Step Verification is enabled, you should see an additional option under "Signing In To Google" called "App Passwords"
   6) Select "App Passwords"; reenter your password
   7) Select "Select App" and go to "Other (Custom Name)"
   8) Create your App Name, then select "Generate"
   9) You will then get a popup box that will display your App Password (4 sets of 4 characters). Capture the password.
 
On 123's SSMTP Module (sys://Schema/Modules/SSMTP/Classes/SMTPConfiguration/):
         SMTPServer:       smtp.gmail.com
          SMTPTimeout:    30
          SMTPAccount:    Your Gmail username (or the one you created)
          SMTPPassword: The 4 character set password (your App Password)
          SMTPUseSSL:    True
          SMTPSSLPort:    465
 
I've ran this for a few days of messages without a hitch...
 
Thanks for sharing!
This recipe works like magic, I tried desperately to send email notifications from Premise via Gmail. I recently had the task of monitoring a sewage pump for failure and remembered my Premise server in the basement.
P.S. My Premise setup is in a semi-abandoned state, and now I'm serious about spending some time updating and integrating with new technologies.
 
Glad you found it helpful!
It's pretty dead here, most other folks have moved on.
A lot of stuff I do now is via Alexa, but Premise I keep running, primarily for monitoring.
 
If you're going to build some new stuff, that would be fantastic. I have a Russound MCA-66 module I'll put up...
 
Back
Top