Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer EHLO #7

Open
cheburah opened this issue Dec 13, 2023 · 5 comments
Open

Answer EHLO #7

cheburah opened this issue Dec 13, 2023 · 5 comments

Comments

@cheburah
Copy link

cheburah commented Dec 13, 2023

Thanks, it works when using public mail. But I have my own mail server installed. When launched, the utility passes an incorrect host name. The host is mfu, the utility sends the name mfu\r\n, postfix responds with EHLO mfu\r\n, the utility says

WARNING: Email failed, disabled until next restart. The server returned an invalid response to the EHLO command.

Can this be fixed somehow?

@MV10
Copy link
Owner

MV10 commented Dec 13, 2023

Interesting. Unfortunately I'm not equipped to test this myself, but the send process is entirely handled by the .NET SmtpClient. The server is referenced and the send operation happens here in Notify.SendEmail:

https://github.com/MV10/UPSMonitor/blob/master/UPSMonitorService/InjectedServices/Notify.cs#L85

using var smtp = new SmtpClient(config.Email.MailServerDomain, config.Email.MailServerPort);
smtp.EnableSsl = config.Email.UseTLS;
smtp.Credentials = config.Email;

await smtp.SendMailAsync(email);

The problem might be in the .NET client. Microsoft actually recommends against using it since it's inefficient and doesn't support a lot of newer standards -- not that any of those apply here. Looking at the other piece of the puzzle, I'd be even more surprised if the CRLF is added when config is read, that also uses .NET's off-the-shelf config-to-class mapping code in the Config class constructor:

https://github.com/MV10/UPSMonitor/blob/master/UPSMonitorService/InjectedServices/Config.cs#L17

Email = config.GetSection("Email").Get<EmailConfig>();

If you're a developer, you might try adding a line at the end of the Config constructor to remote CRLF:

Email.MailServerDomain = Email.MailServerDomain.Replace("\r","").Replace("\n","");

If that works, I'll either accept a PR or make the change myself and drop a new release. I was thinking about bumping this to .NET8 anyway. If that doesn't work, I suppose we could try a third-party mail client (MS recommends MailKit although it's relatively huge).

Let me know if you have the ability to test code changes. If not, I'll drop a binary here for you to test.

@cheburah
Copy link
Author

I'm not a developer, if you send me a binary, I will be grateful

@MV10
Copy link
Owner

MV10 commented Dec 14, 2023

I built a new binary for the Windows service -- execute stop.cmd, copy the files from the zip to your app directory, then execute run.cmd. The file is too big to attach here (github only allows up to 25MB, this is 36MB) so I attached it on the release page as service_cheburah.zip. Once you download it, let me know so I can remove that so nobody else gets confused.

However, I don't expect this to fix anything. SMTP commands are required to end with a CRLF sequence, per the RFC section 2.3.8, and section 4.1.1.1 specifically shows EHLO sequences ending with CRLF. I also can't find any other mention of this problem and the .NET classes for this are very old and haven't changed in a long time.

Obvious question: I assume you're using this mail server successfully with other SMTP clients? I think it's probably something with your mail server, but it's easy enough to try the fix I mentioned. If this doesn't work, I'm willing to update the project to use the third-party library recommended by MS, but that will take some time.

Please let me know the results either way.

@cheburah
Copy link
Author

Thank you for your response. The error remains.
I have a mail server only for sending notifications about events: monitoring UPS, the Internet, server states, etc. When using public mail, when the wired Internet is lost, messages do not arrive, it takes time to switch to the mobile channel. My mail server sends until it sends.
Therefore, I use a very limited number of mailing sources, the built-in Mikrotik mail service, UPSMON-PRO. I have now found PowerChute Serial Shutdown v1.0 and they all work with my mail server. And, when trying to simply send EHLO via telnet, there is also no distortion.
In any case, thanks for your participation, I'm happy with the PowerChute Serial Shutdown I found

@MV10
Copy link
Owner

MV10 commented Dec 14, 2023

Ok. I'll keep this open and ping you again when I update to the other mail client, in case you want to try again.

I'd be wary of the APS products. They were bought by another company and most of the older apps will be discontinued early next year. The newer ones, well ... I wasn't too impressed. There are details in my article (linked in the README) about this application, if you haven't read that yet.

Anyway -- thanks for reporting this and good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants