3

Now, as the Lesser secure apps feature in Gmail has been disabled, I am trying to find alternatives for email sending. I am trying freemail.hu as an alternative which supports SMTP protocol, but any other suggestion is highly welcome.

According to the web page, the data for SMTP are the following:

  • Server name: smtp.freemail.hu
  • Port: 587 (with STARTTLS)
  • Username: email address
  • Password: the same as used on the web

My code looks like this:

import smtplib
import ssl

try:
    server = smtplib.SMTP('smtp.freemail.hu', 587)
    server.starttls(context=ssl.create_default_context())
    server.login('[myuser]@freemail.hu', '[mypassword]')
    server.sendmail('[myuser]@freemail.hu', ['[myprivatemail]@gmail.com'], 'Test mail.')
except Exception as e:
    print(e)
finally:
    server.quit()

The username is password is correct: I checked them several times + it works on the web interface. However, I am getting the following error message:

(535, b'5.7.8 Error: authentication failed: [encoded value]')

Does anyone has an idea what the problem could be?

I tried two email providers (freemail.hu, mail.com), tried to log in with and without server name, tried to enter the password from command prompt, checked the settings looking for the feature similar to Lesser secure apps in Google, but nothing helped.

  • Are you 100% sure you need to supply the domain when you login? Have you tried doing it without the domain? – Tim Roberts Nov 10 '22 at 22:20
  • 1
    About: `as the Lesser secure apps feature in Gmail has been disabled, I am trying to find alternatives for email sending`. You can now create [app passwords](https://support.google.com/mail/answer/185833?hl=en-GB) using a gmail account and use that unique password on `server.login('[myuser]@freemail.hu', '[mypassword]')`. I'm currrently using app passwords, and they worked with no problems. Same script you provided btw. – Carl HR Nov 10 '22 at 22:32
  • I'd suggest you sanitize that text for public consumption. – Kenny Ostrom Nov 11 '22 at 01:31
  • I tried without domain name as well. I'll try app password. What do you mean 'sanitize'? – Csaba Faragó Nov 11 '22 at 09:41
  • Carl, I tried the app passwords and it works. If you post is as an answer with some details, I'll accept is as answer of the question, otherwise I answer it myself. – Csaba Faragó Nov 14 '22 at 08:05

2 Answers2

0

For Gmail the App Passwords as described on page https://support.google.com/mail/answer/185833 works well. The 2 step verification should be turned on, and then a 16 character long random password can be generated on the App passwords section.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 21 '22 at 12:18
0

Every tried ofunctions.mail package ? Deals with ssl and tls, attachments, encoding, etc.

Install with pip install ofunctions.mailer

Usage

from ofunctions.mailer import Mailer

recipients = ['me@example.com', 'them@example.com', 'anyone@example.com', 'malformed_address_at_example.com']

mailer = Mailer(smtp_server='mail.example.com', smtp_port=465, security='ssl', debug=True, verify_certificates=False)

# split_mails=True will send one email per recipient
# split_mails=False will send one email for all recipients, which will be limited to the number of recipients the destination SMTP server allows
mailer.send_email(subject='test', sender_mail='me@example.com', recipient_mails=recipients, body='some body just told me', split_mails=True)

Just replace ssl with tls or None if needed.

See more usecases at github

disclaimer: I'm the author of ofunctions package.

Orsiris de Jong
  • 2,819
  • 1
  • 26
  • 48