anoved / OctoPrint-EmailNotifier

Receive email notifications when OctoPrint jobs are complete. Currently broken. Please fork and fix!
GNU Affero General Public License v3.0
16 stars 35 forks source link

Feature request: Support for SMTP server without validation #36

Open bipsendk opened 7 years ago

bipsendk commented 7 years ago

It would be nice, if the plugin supported to use a standard SMTP server (that allows relaying) without having to enter user credentials.

automatedelectrics commented 5 years ago

It maybe a bit late to help with this particular problem, but it might help someone else in the future ...

I was stuck with the same issue recently where I tried to set up Email Notifier without authentication because we run our own email server locally and sending an email from a client will fail if we try to use any type of authentication.

In the end the solution which worked for us was;

  1. SSH into OctoPi and open the file __init__.py which was located under /home/pi/oprint/lib/python2.7/site-packages/octoprint_emailnotifier
  2. At the end of the file, comment out the line; mailer = yagmail.SMTP(user={self._settings.get(['mail_username']):self._settings.get(['mail_useralias'])}, host=self._settings.get(['mail_server']),port=self._settings.get(['mail_server_port']), smtp_starttls=self._settings.get(['mail_server_tls']), smtp_ssl=self._settings.get(['mail_server_ssl']))
  3. Add a new line directly under with the following; mailer = yagmail.SMTP(user=self._settings.get(['mail_username']), password=None, host=self._settings.get(['mail_server']), port=self._settings.get(['mail_server_port']), smtp_skip_login=True, smtp_starttls=self._settings.get(['mail_server_tls']), smtp_ssl=self._settings.get(['mail_server_ssl']))
  4. Save and reboot the Pi.

The key changes to the original line were; Removed self._settings.get(['mail_useralias']) (we didn't need the alias parameter) Added password=None (you still need a username for the "From" section of the email, but no P/W) Added smtp_skip_login=True (this was the big one!)

You can directly edit the existing line if you like, but I always like to keep the original code as a reference (particularly when testing) or just in case something goes wrong and you need to revert back.

Additionally, we also needed to add our desired username to a new file in the home directory which caused another error (because the yagmail was looking for this file, which was missing). The username is just used for the "From" section of the email sent, and in our case it didn't even need to be a valid user on our email system (update the "{ }" sections in the following to suit). echo {Username}@{Email Address} > ~/.yagmail

I hope this helps!

OctoPrint Email Notifier Settings Example for No SMTP Authentication email notifier example settings