I
I
Ivan2017-01-21 13:55:09
Python
Ivan, 2017-01-21 13:55:09

How to send email from mail.ru in Python?

Here is such a script that perfectly sends a letter from gmail to mail.ru, if in the Gmail settings you allow access to mail to unverified applications.

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
 
fromaddr = "[email protected]"
toaddr = "[email protected]"
mypass = "password"
 
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Привет от питона"
 
body = "Это пробное сообщение"
msg.attach(MIMEText(body, 'plain'))
 
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, mypass)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

But if I try to send a letter not through Gmail, but through Mail.ru, using the mail smtp, I get a bunch of errors and nothing is sent. Why?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
T
Tahir B, 2018-06-15
@Tahir87

Already, I think, irrelevant, but still I will answer:
replace

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()

on the
server = smtplib.SMTP_SSL('smtp.mail.ru', 465)

A
Alexander, 2017-01-21
@fireSparrow

Try changing the port to 465.
This port is listed on the official mail.ru website:
https://help.mail.ru/mail-help/mailer/popsmtp

D
Dimonchik, 2017-01-21
@dimonchik2013

fromaddr = "[email protected]"
toaddr = "[email protected]"

changed?

A
Artem Melnykov, 2019-03-03
@NickProgramm

It is difficult to make friends with Mail.ru and python, it is better to use gmail
solkogan.ru

K
krared, 2021-10-12
@krared

Create a password if there is a two-factor.
It is necessary to put port 25, google here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question