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.

5
  • Are you 100% sure you need to supply the domain when you login? Have you tried doing it without the domain? Commented Nov 10, 2022 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 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. Commented Nov 10, 2022 at 22:32
  • I'd suggest you sanitize that text for public consumption. Commented Nov 11, 2022 at 1:31
  • I tried without domain name as well. I'll try app password. What do you mean 'sanitize'? Commented Nov 11, 2022 at 9: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. Commented Nov 14, 2022 at 8:05

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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 = ['[email protected]', '[email protected]', '[email protected]', '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='[email protected]', 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.