Any new ideas how to get email working in HG?

I have hours into experimenting with different ideas I have found online for making email send in HG. None have worked. I am on ver .37, mono 5.4.0.201, tried gmail, yahoo, and my own server smtp, none send.

Log shows error as:

2019-02-24 11:52:07.1672 Trace SendMessage: going to send email System.Net.Mail.MailMessage using mailService ‘smtp.gmail.com’, port ‘465’, credentials System.Net.NetworkCredential, using SSL = True

then:

2019-02-24 11:52:17.4956 Trace SendMessage: error sending email {0}
2019-02-24 11:52:17.5003 Error System.Net.Mail.SmtpException: Message could not be sent. —> System.IO.IOException: Connection closed
at System.Net.Mail.SmtpClient.Read () [0x000bd] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00084] in <8a8abae728c244359683ef777047ab9e>:0
— End of inner exception stack trace —
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x0009f] in <8a8abae728c244359683ef777047ab9e>:0
at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003f1] in <b08d74f9b7fb4c85b616d2d9beee8275>:0
2019-02-24 11:52:17.5211 Error HomeAutomation.HomeGenie.Automation
at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003f1] in <b08d74f9b7fb4c85b616d2d9beee8275>:0
2019-02-24 11:52:17.5225 Trace SendMessage: disposing smtpClient
2019-02-24 11:52:17.5264 Trace SendMessage: called for recipients [email protected]
2019-02-24 11:52:17.5310 Trace SendMessage: getting smtpSyncLock
2019-02-24 11:52:17.5323 Trace SendMessage: got smtpSyncLock
2019-02-24 11:52:17.5378 Trace SendMessage: going to send email System.Net.Mail.MailMessage using mailService ‘smtp.gmail.com’, port ‘465’, credentials System.Net.NetworkCredential, using SSL = True

I assume this is the certificate issue in mono so often spoken about?

Any help?

I make GREAT use of a program written by a HG user “jshan” that allows me to send informational emails from within HG triggered by programs.
I suggest taking a look at the old forum and looking for the program. Sorry I do not remember the name of the program only the writer.

@mike if you have a spare SD card write a new image and a fresh install of HG (don’t install your backup) configure your email and try a HG email send.
If it works then install your HG backup and test a email send again again.
I have no issues with sending emails with any version of HG (never have) so I suspect either your HG backup or your SD image or HG install is bad.

I solved my e-mail sending issues by importing the certificates like below.
I am on raspian 4.9.70-v7+ mono 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:34:50 UTC 2016),
HG runs for hundred days without any issue.

replace url:port with the settings of your e-mail provider you gonna use

enter as root:
certmgr -ssl smtps://url:port
cert-sync /etc/ssl/certs/ca-certificates.crt
certmgr -ssl smtps://url:port
mozroots --import --ask-remove --machine

I did the same as user pi, not sure whether this is really needed.

I just checked gmail, works, too

echo “” | openssl s_client -tls1 -showcerts -connect smtp.gmail.com:465

Thanks!

My research seems to say >3.0 mono does not even use mozroots, so that line should not be required.

My research seems to say >5.0 mono does not need certmgr, so that line should not be required.

I have done both anyway. :slight_smile: I got mine to say it imported both gmail and yahoo ssl certificates.

Meanwhile, back at the farm, I have an email that does not use SSL: it too does not work here. (:

Have you tried port 587 as I suggested. Have you confirmed that SSL is ticked in the email configuration account. Have you used port checker to find out if the relevant ports are opened and listening for that service. Does your isp allow this service on those ports.

@mike, take a look at this question on StackOverflow, may be it will help https://stackoverflow.com/questions/39724474/client-email-c-sharp

  1. Have you tried port 587 as I suggested.
    – yes, both 465 & 587 on all 3 accounts (gmail, yahoo & non SSL private account)
  2. Have you confirmed that SSL is ticked in the email configuration account.
    – yes, and unticked on trying my non SSL email
  3. Have you used port checker to find out if the relevant ports are opened and listening for that service.
    – no as I use both these ports on many computers on this intranet every minute
  4. Does your isp allow this service on those ports.
    – yes. They shut off port 25 a year ago and we have switched all (10-15?) email accounts here over to either 465 or 587 since.

I assume you don’t use two step verification and you have less secure apps enabled in Google.

There hasn’t been an issue with email notification in HG since Mono 5.4 and I can confirm that the standard email notification program supplied as it is works fine.

Any modification to that program I can’t and won’t comment on as I’ve no idea how it is being edited and compiled.

When you are installing HG from the homegenie.it you may want to change the source to Mono to 5.4 by editing your apt sources list and doing so prior to installing HG.

There’s plenty of posts on the forum on how to do that.

Can you send emails from this RPi/PC using another software?

Thanks Bounz. I checked out the thread on io exception you mentioned, and all its offshoots. I have a feeling it is something else, so I have a fresh pi running and plan to load HG on it next to try. I do not have any other software on the pi other than HAbridge so no other email testers.

Try to use this program to test email sending: EmailTester.exe (6.5 KB)

You can run it with mono EmailTester.exe command.

@Bounz it would be interesting to see exactly what email notification program the OP is using. Is it the one from the original HG forum or has it been modified in some way. Is it compiling correctly without errors in HG. Maybe info like this would help you troubleshoot this matter a little easier.

The OP is using Mono 5.4 so I see no reason why certificates should be an issue in this case. The email notification program is working here in its original unmodified form with no problems.

The OP is using the default HG email sender program. No midifications. The OP posted his log files showing the error. It compliles fine, no errors. The OP even has a non SSL email account he has tried, setting SSL support to both on and off. The OP has now started a totally separate pi with new HG program, and it faults the same way. Thank you bounz for your mono email seperate program. This OP will be tryng it as soon as he gets a chance, and will report back. Thank you!

That’s good to hear. There’s modified versions of the original email notification program circulating that do not compile properly. Hacked versions of the original code.

Maybe you could download a copy of VS2017 and compile the program for yourself. It’s an easier environment to work in as it has an IDE that can check your syntax to rule out obvious syntax errors.

The original version of the email notification program is working fine with both HG BE v1.1.22 and HG v.1.2 stable .38. Both were tested with Mono 5.4

Bounz

1d

Try to use this program to test email sending: EmailTester.exe (6.5 KB)

You can run it with mono EmailTester.exe command.

DONE. FAILED. (NOT SSL)

[email protected]:/tmp $ mono EmailTester.exe
Email receiver address: [email protected]
Email sender address: [email protected]
SMTP server (default value = smtp.gmail.com): xxxxxashere.com
SMTP port (default value = 587):
SMTP user name: [email protected]
SMTP user domain (leave blank, if you don’t know):
SMTP password: xxxxxxxxxxxxxxx
Use SSL? (1-yes, 0-no) (default value = 1): 0

System.Net.Mail.SmtpFailedRecipientsException: failed recipients
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x002f3] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00091] in <8a8abae728c244359683ef777047ab9e>:0
at EmailTester.Program.Main (System.String[] args) [0x000c2] in :0

Bounz, thank you very much fo rthis program to test my system! I will spend more time next trying gmail and yahoo email addresses.

so tried gmail account, same no go:

[email protected]:/tmp $ mono EmailTester.exe
Email receiver address: [email protected]
Email sender address: [email protected]
SMTP server (default value = smtp.gmail.com): smtp.gmail.com
SMTP port (default value = 587): 465
SMTP user name: [email protected]
SMTP user domain (leave blank, if you don’t know):
SMTP password: xxxxx
Use SSL? (1-yes, 0-no) (default value = 1): 1

System.Net.Mail.SmtpException: Message could not be sent. —> System.IO.IOException: Connection closed
at System.Net.Mail.SmtpClient.Read () [0x000bd] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00084] in <8a8abae728c244359683ef777047ab9e>:0
— End of inner exception stack trace —
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x0009f] in <8a8abae728c244359683ef777047ab9e>:0
at EmailTester.Program.Main (System.String[] args) [0x000c2] in :0
System.IO.IOException: Connection closed
at System.Net.Mail.SmtpClient.Read () [0x000bd] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00084] in <8a8abae728c244359683ef777047ab9e>:0
[email protected]:/tmp $

Just to check that this is not a network related problem, try to do this from your machine:

telnet smtp.gmail.com 465

Then you will need to press Ctrl+] to terminate the session and type quit in telnet> prompt to quit from telnet.

Please, share the results of telnet here.

I forgot how to get my cmd window to allow telnet; tried 2 different windows computers:

C:\Users\mike\OneDrive\Desktop>telnet
DNS server not authoritative for zone.

So I used putty set to telnet:

  • trying port 465 it crashes putty with error "server unexpectedly closed network connection.
  • using port 587 it seems to connect, saying immediately:
    220 smtp.gmail.com ESMTP z126sm15956508qkz.8 - gsmtp
  • then if I send nonsense it says:
    hi bob
    502 5.5.1 Unrecognized command. z126sm15956508qkz.8 - gsmtp

If I send GET it closes the putty session.

I use thunderbird for emails here on most computers, and so use smtp.gmail and other servers FWIW.

This makes sense. This error is the same as you get in HG and EmailTester when it says System.IO.IOException: Connection closed. Something in your network blocks connections to smtp.gmail.com:465.
I recommend you to use the same settings as you use in Thunderbolt. Also, as you are a Windows user, there should be no problem with security certificates.