diff --git a/MastodonFeedHTML/Example.Config.py b/MastodonFeedHTML/Example.Config.py index e3adbff..c21c023 100644 --- a/MastodonFeedHTML/Example.Config.py +++ b/MastodonFeedHTML/Example.Config.py @@ -11,10 +11,11 @@ Feeds = [ ] # SMTP configuration (only required for sending mail). -MailUsername = "example@example.com" +MailUsername = "example@example.com" # Your full email address. MailPassword = "Example" MailServer = "smtp.example.com" -MailPort = 465 +MailPort = 465 # (Usually) 465 for SSL, 587 for TLS, 25 for No encryption. +MailEncryption = "SSL" # SSL, TLS, or None. # How often to refresh the feeds (in seconds). Set to 0 for a single run, instead of having the program sleep. LoopTime = 300 diff --git a/MastodonFeedHTML/MastodonFeedHTML.py b/MastodonFeedHTML/MastodonFeedHTML.py index abeb9a8..fd29d45 100755 --- a/MastodonFeedHTML/MastodonFeedHTML.py +++ b/MastodonFeedHTML/MastodonFeedHTML.py @@ -55,9 +55,9 @@ def HandleFeed(URLs, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo LastEntryIsNew, PageOlder = HandleURL(True, URL, Usertag, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo) if LastEntryIsNew and PageOlder: Pages += [PageOlder] - while LastEntryIsNew and PageOlder and len(Pages) < MaxPagesRecursion: + while LastEntryIsNew and PageOlder and (MaxPagesRecursion <= 0 or len(Pages) < MaxPagesRecursion): LastEntryIsNew, PageOlder = HandleURL(True, PageOlder, Usertag, IncludeRetoots, IncludeReplies, LocalSave, SendMail, MailTo) - if LastEntryIsNew and PageOlder and MaxPagesRecursion: + if LastEntryIsNew and PageOlder: Pages += [PageOlder] Pages.reverse() for Page in Pages: @@ -171,9 +171,20 @@ def HandleURL(IsFirstRun, URL, Usertag, IncludeRetoots, IncludeReplies, LocalSav .replace('{ Replace:MastodonFeedHTML:MediaDescs }', MakeMediaDescsBlock(MediaDescs)), 'html')) for File in MailAttach: Message.attach(File) - with smtplib.SMTP_SSL(MailServer, MailPort, context=ssl.create_default_context()) as Client: - Client.login(MailUsername, MailPassword) - Client.sendmail(MailUsername, MailTo, Message.as_string()) + + if MailEncryption.lower() == 'ssl': + Mailer = smtplib.SMTP_SSL(MailServer, MailPort, context=ssl.create_default_context()) + elif MailEncryption.lower() in ('tls', 'none'): + Mailer = smtplib.SMTP(MailServer, MailPort) + if MailEncryption.lower() == 'tls': + Mailer.starttls(context=ssl.create_default_context()) + else: + print("[E] MailEncryption variable is set incorrectly. Cannot continue. Please check your config.") + exit(1) + + Mailer.login(MailUsername, MailPassword) + Mailer.sendmail(MailUsername, MailTo, Message.as_string()) + Mailer.quit() SleepPrint(MailSleep) if LocalSave: